Flavius Alecu wrote:
I've read all about fractals, mandelbrot set, julia set all that...and I
read about generating 3d terrains...but I still can't implement a simple
algorithm for 2d terrain.
I know the midpoint displacement method but I wasn't able to make an
algorithm of it...does anyone know of a thing like that or is willing to
explain a little how this could be achieved??
thanx a lot
// For Mandelbrot Set
public void paint(Graphics g) {
Image img;
int w = 256;
int h = 256;
int[] pix = new int[w*h];
int index = 0;
int iter;
double a, b;
double p, q, psq, qsq, pnew, qnew;
for( int y = 0; y < h; y++) {
b = ((double)(y - 128))/64;
for (int x = 0; x < w; x++) {
a = ((double)(x - 128))/64;
p = q = 0.0;
iter = 0;
while(iter < 32) {
psq = p*p;
qsq = q*q;
if(psq + qsq >= 4.0)
break;
pnew = psq - qsq + a;
qnew = 2*p*q + b;
p = pnew;
q = qnew;
iter++;
}
if (iter == 32)
pix[index] = 255 << 24 | 255;
index++;
}
}
img = createImage(new MemoryImageSource(w, h, pix, 0, w));
g.drawImage(img, 0, 0, null);
}
Refer: http://www.hewgill.com/chaos-and-fractals/ to know more then what
you have read till now!
--
Vicky Budhiraja
R&D Programmer
www.kirnoarth.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".