Sebaall

Mandelbrot

Nov 30th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.io.*;
  2. class Pixel{
  3.    
  4.     static String kolor(int n){
  5.                             double R=(255.-255.*Math.pow(0.9,n));
  6.                             double G=(255.-100.*Math.pow(0.97,n));
  7.                             double B=(255.-60.*Math.pow(0.88,n));
  8.                             return (int)R+" "+(int)G+" "+(int)B+"\n";
  9.     }
  10.        
  11. }
  12. class Mandelbrot {
  13.      static void create(int SZER, int WYS, int MAX){
  14.         double x,y;
  15.         int k;
  16.         BufferedWriter writer = null;
  17.             try
  18.             {
  19.                 writer = new BufferedWriter( new FileWriter("mandel.ppm"));
  20.                 writer.write("P3\n# obraz\n"+SZER+" "+WYS+"\n255\n");
  21.                 for(y=-1.25;y<1.25;y=y+(2.5/WYS))
  22.                     {
  23.                         for(x=-2.;x<1.;x=x+(3./SZER))
  24.                         {
  25.                             Complex c=new Complex(x,y);
  26.                            
  27.                             k=0;
  28.                             for(Complex z=new Complex(0.,0.);Complex.abs(z)<2. && k<MAX;k++)
  29.                                     z=Complex.add(Complex.pow(z,2),c);
  30.                             writer.write(Pixel.kolor(k));
  31.                    
  32.                            
  33.                         }
  34.                                
  35.                     }
  36.  
  37.  
  38.             }
  39.             catch ( IOException e)
  40.             {
  41.             }
  42.             finally
  43.             {
  44.                 try
  45.                 {
  46.                     if ( writer != null)
  47.                         writer.close( );
  48.                 }
  49.                 catch ( IOException e)
  50.                 {
  51.                 }
  52.              }                       
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment