HP Prime for All

English  Русский 
Julia graphics-app screenshot}}
Name Julia
Description Inspired by the Mandelbrot generator, this has been modified to display the Julia set.
Author Wolfgang Weber

Source code (download):

Source code formatted by website engine

WWclr(Ndx) BEGIN Ndx := ROUND(Ndx*192, 0); IF Ndx < 32 THEN RETURN 0+8*Ndx; END; IF Ndx < 64 THEN RETURN 255 + (8 * (Ndx-32)) * 256; END; IF Ndx < 96 THEN RETURN 65535-8 * (Ndx-64); END; IF Ndx < 128 THEN RETURN 65280 + (8 * (Ndx-96)) * 65536; END; IF Ndx < 192 THEN RETURN 16776960 - (4 * (Ndx-128)) * 256; END; RETURN 16777215; END; j_iteration(z, c, bailoutValue, maxIter) BEGIN LOCAL iter := 0; WHILE (ABS(z) < = bailoutValue) AND (iter < maxIter) DO z := z*z+c; iter := iter+1; END; RETURN iter; END; j_colorize(itVal, maxIt) BEGIN IF itVal == maxIt THEN // we're inside the Julia map // so draw the pixel in white RETURN 0; //16777215; ELSE RETURN WWclr(itVal/maxIt); END; END; EXPORT Julia() BEGIN // clear the screen (G0): RECT(); LOCAL dx, dy, z, c, xp, yp; LOCAL iter, color; // these 4 variables define // our window of the complex // plane: LOCAL xmin, xmax, ymin, ymax; LOCAL maxIterations := 50; LOCAL maxRadius := 1000; // Location // ratio width:height should be 4:3 xmin := -1.6; xmax := 1.6; ymin := -1.2; ymax := 1.2; c := (−0.8, 0.2); // c := (-1, 0); // another nice set of parameters: xmin := 0.315625; xmax := 0.515625; ymin := 0.28125; ymax := 0.43125; dx := (xmax-xmin) / 320; dy := (ymax-ymin) / 240; z := (xmin, ymin); // we loop over every pixel // of the Prime's screen: FOR yp FROM 0 TO 239 DO FOR xp FROM 0 TO 319 DO // create the complex number c // we need for the iteration: z := (xmin+xp*dx, ymax-yp*dy); // now iterate the formula and // get back the number of // iteration steps it took until // the complex number jumped out // of the convergence radius: iter := j_iteration(z, c, maxRadius, maxIterations); // determine a color for this iteration number: color := j_colorize(iter, maxIterations); // set the pixel in that color: PIXON_P(xp, yp, color); END; END; // leave the image on the screen // until a key is pressed: REPEAT UNTIL GETKEY() == -1; FREEZE; END;

Comments