All pastes #705929 Raw Edit

bwMandelbrot.java

public java v1 · immutable
#705929 ·published 2007-09-21 14:19 UTC
rendered paste body
// Simple Java Applet to generate a black and white Mandelbrot set// Written by phgod on 20050721import java.applet.*;import java.awt.*;public class bwMandelbrot extends Applet {  int width, height;  public void init() {    // The calling HTML determines the size    width = getSize().width;    height = getSize().height;    setBackground( Color.white );  }  public void paint(Graphics g) {    final int a_MIN=1, a_MAX=width-2, b_MIN=1, b_MAX=height-2;    final int da=1, db=1;    // The bounding box    g.setColor(Color.black);    g.drawRoundRect(a_MIN, b_MIN, a_MAX, b_MAX, 15, 15);    for(int ia=a_MIN; ia<a_MAX; ia+=da){      for(int ib=b_MIN; ib<b_MAX; ib+=db){        if(IsFinite(3.*(ia-a_MIN)/(a_MAX-a_MIN)-2., 2.*(ib-b_MIN)/(b_MAX-b_MIN)-1.)){          g.fillOval(ia, ib, 2, 2);        }      }    }    // Print the title    g.setColor( Color.red );    g.drawString( "Mandelbrot set in Java applet", 10, 20);  }  // A point should be drawn if the iteration does not diverge.  // Draw the point if this function returns true.  private boolean IsFinite(double a, double b){    final int N_TEST=200;    double x=0, y=0, oldx, oldy;    for(int nTest=0; nTest<N_TEST; nTest++){      oldx=x;	oldy=y;       // Iteration: z = (z0)^2 + (a+bi)      x=oldx*oldx-oldy*oldy+a;      y=2*oldx*oldy+b;      // Regard as divergence if |z|>2      if(x*x+y*y>4) return false;    }    return true;  }}