ソース:
import java.awt.*;
import java.applet.Applet;
public class Mandelbrot extends Applet {
static final int MAXITER = 200;
Image img;
int count(double x, double y) {
double a = x, b = y;
for (int i = MAXITER; i > 0; i--) {
double a2 = a * a, b2 = b * b;
if (a2 + b2 > 4) return i;
b = 2 * a * b - y; a = a2 - b2 - x;
}
return 0;
}
public void init() {
int width = getWidth();
int height = getHeight();
double xorig = Double.parseDouble(getParameter("xorig"));
double yorig = Double.parseDouble(getParameter("yorig"));
double d = Double.parseDouble(getParameter("d"));
Color[] colors = new Color[MAXITER + 1];
colors[0] = Color.BLACK;
for (int i = 1; i < colors.length; i++) {
float h = (float) Math.pow((double) i / colors.length, 6);
colors[i] = Color.getHSBColor(0.666667f * h, 1f, h);
}
img = createImage(width, height);
Graphics g = img.getGraphics();
for (int i = 0 ; i < width; i++) {
double x = xorig + d * i;
for (int j = 0; j < height; j++) {
double y = yorig + d * j;
g.setColor(colors[count(x, y)]);
g.fillRect(i, (height - 1 - j), 1, 1);
}
}
}
public void paint(Graphics g) {
g.drawImage(img, 0, 0, this);
}
public void update(Graphics g) {
paint(g);
}
}
Last modified: 2005-12-29 23:21:16