|
-
Oct 2nd, 2006, 11:32 PM
#1
Thread Starter
Fanatic Member
Help with drawing
im trying to duplicate a really neat java applet i saw on the web ( source code was free)
but part of the program sets up a "drawing area"
Code:
void setup() {
// set up drawing area
size(800,800,P3D);
background(0);
// take it nice and easy
framerate(15);
// load typeface
metaBold = loadFont("Arial-48.vlw");
}
and im not sure what the eqivlantcy is in C# i set up a picture box but im not sure how to set up c# to change it pixel by pixel like the java program does
any pointers
-
Oct 2nd, 2006, 11:33 PM
#2
Thread Starter
Fanatic Member
Re: Help with drawing
here is the entire source code if needed
Code:
// j.tarbell January, 2004
// Albuquerque, New Mexico
// complexification.net
// based on code by Paul Bourke
// astronomy.swin.edu.au/~pbourke/
// Processing 0085 Beta syntax update
// j.tarbell April, 2005
int dim = 800; // screen dimensions (square window)
int bailout = 200; // number of iterations before bail
int plots = 10000; // number of plots to execute per frame (x30 = plots per second)
// 2D array to hold exposure values
int[] exposure = new int[dim*dim];
int maxexposure; // maximum exposure value
int time = 0;
int exposures = 0;
boolean drawing;
PFont metaBold;
// MAIN ----------------------------------------------------------------
void setup() {
// set up drawing area
size(800,800,P3D);
background(0);
// take it nice and easy
framerate(15);
// load typeface
metaBold = loadFont("Arial-48.vlw");
}
void draw() {
plotPlots();
time++;
if (time%30==0) {
// show progress every 2 seconds or so...
findMaxExposure();
renderBrot();
// show exposure value
fill(255);
noStroke();
textFont(metaBold, 14);
text("bailout: "+bailout+" exposures: "+exposures, 5, dim-6);
}
}
void plotPlots() {
float x, y;
// iterate through some plots
for (int n=0;n<plots;n++) {
// Choose a random point in same range
x = random(-2.0,1.0);
y = random(-1.5,1.5);
if (iterate(x,y,false)) {
iterate(x,y,true);
exposures++;
}
}
}
void renderBrot() {
// draw to screen
for (int i=0;i<dim;i++) {
for (int j=0;j<dim;j++) {
float ramp = exposure[i*dim+j] / (maxexposure / 2.5);
// blow out ultra bright regions
if (ramp > 1) {
ramp = 1;
}
color c = color(int(ramp*255), int(ramp*255), int(ramp*255));
set(j,i,c);
}
}
}
// Iterate the Mandelbrot and return TRUE if the point exits
// Also handle the drawing of the exit points
boolean iterate(float x0, float y0, boolean drawIt) {
float x = 0;
float y = 0;
float xnew, ynew;
int ix,iy;
for (int i=0;i<bailout;i++) {
xnew = x * x - y * y + x0;
ynew = 2 * x * y + y0;
if (drawIt && (i > 3)) {
ix = int(dim * (xnew + 2.0) / 3.0);
iy = int(dim * (ynew + 1.5) / 3.0);
if (ix >= 0 && iy >= 0 && ix < dim && iy < dim) {
// rotate and expose point
exposure[ix*dim+iy]++;
}
}
if ((xnew*xnew + ynew*ynew) > 4) {
// escapes
return true;
}
x = xnew;
y = ynew;
}
// does not escape
return false;
}
void findMaxExposure() {
// assume no exposure
maxexposure=0;
// find the largest density value
for (int i=0;i<dim;i++) {
for (int j=0;j<dim;j++) {
maxexposure = max(maxexposure,exposure[i*dim+j]);
}
}
}
}
}
-
Oct 3rd, 2006, 12:05 AM
#3
Re: Help with drawing
I would guess that drawing in Java is fairly different to drawing in .NET. Forget converting code and think about the end result. Decide what you want to happen and then look at the best way to accomplish that result in C#. It may be nothing like the Java code. Drawing in .NET is done using GDI+, mostly through the Graphics class. You should read some .NET GDI+ tutorials.
-
Oct 3rd, 2006, 12:35 AM
#4
Thread Starter
Fanatic Member
Re: Help with drawing
ill give it a try
ill let you know how it goes
-
Oct 3rd, 2006, 01:15 AM
#5
Re: Help with drawing
By the way, this is not Java this is javascript
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Oct 3rd, 2006, 01:23 AM
#6
Thread Starter
Fanatic Member
Re: Help with drawing
ah
sorry
im just glad i noticed it as java anything
-
Oct 3rd, 2006, 06:57 AM
#7
Re: Help with drawing
I hope you are going to optimize that before you translate it.
I don't live here any more.
-
Oct 3rd, 2006, 02:54 PM
#8
Thread Starter
Fanatic Member
Re: Help with drawing
i hope you suggest some optimizeations
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|