Advertisement
calcpage

LACS08_Mandel.java

Jun 18th, 2012
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.35 KB | None | 0 0
  1. /**
  2. Mandel.java     MrG     2012.0620
  3. purpose:    plot mandelbrot fractals
  4. required files: Mandel.java     main class
  5.         Complex.java        derived class
  6.         Picture.java        pixel class
  7. translator: javac Mandel.java
  8.         java Mandel xc yc radius dwell pixels
  9. */
  10. import java.awt.Color;
  11. public class Mandel
  12. {
  13.     public static int limit(Complex z, int dwell)
  14.     {
  15.         Complex z0=z;
  16.         for(int t=0; t<dwell; t++)
  17.         {
  18.             if(z.abs()>2.0)
  19.             {
  20.                 return t;
  21.             }
  22.             z=z.prod(z).sum(z0);
  23.         }
  24.         return dwell;
  25.     }
  26.  
  27.     public static void main(String[] args)
  28.     {
  29.         double xc = Double.parseDouble(args[0]);
  30.         double yc = Double.parseDouble(args[1]);   
  31.         double radius = Double.parseDouble(args[2]);   
  32.         int dwell = Integer.parseInt(args[3]); 
  33.         int pixels = Integer.parseInt(args[4]);
  34.  
  35.         Color color;
  36.         Picture m = new Picture(pixels,pixels);
  37.  
  38.         for(int r=0; r<pixels; r++)
  39.         {
  40.             for(int c=0; c<pixels; c++)
  41.             {
  42.                 double x=xc-radius/2+radius*r/pixels;
  43.                 double y=yc-radius/2+radius*c/pixels;
  44.                 Complex z = new Complex(x,y);
  45.                 int limit = limit(z,dwell);
  46.                 if(limit==dwell)
  47.                 {
  48.                     color = new Color(0,0,0);
  49.                 }
  50.                 else
  51.                 {
  52.                     color = new Color((float)(limit)/dwell,0,0);
  53.                 }
  54.                 System.out.println("limit x y = " + limit + "\t" + x + "\t" + y);
  55.                 m.set(r,c,color);
  56.                 m.show();
  57.             }
  58.         }
  59.         System.out.println("mag = " + Math.pow(2/radius,2));
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement