z0z0z

Untitled

Dec 1st, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. float maxImaginary = 2;
  2. void setup () {
  3.   colorMode(HSB, 360, 100, 100);
  4.   size(8000, 8000);
  5.   fill(0);
  6.   rect(0,0,width,height);
  7.   mandelbrot();
  8. }
  9.  
  10. void draw () {
  11. }
  12.  
  13. void mandelbrot () {
  14.   int maxIterations = 500;
  15.   for (int x=0; x!=height/80; ++x) {
  16.     for (int y=0; y!=width/80; ++y) {
  17.       float real = map(x, 0, width/80, minReal, maxReal);
  18.       float realConst = real;
  19.       float imaginary = map(y, 0, height/80, minImaginary, maxImaginary);
  20.       float imaginaryConst = imaginary;
  21.       int iterations = 0;
  22.             int x1 = int(x*80+map(real, 0, 4, 0, 80));
  23.       int y1 = int(y*80+map(imaginary, 0, 4, 0, 80));
  24.       int x2 = int(x*80+map(real, 0, 4, 0, 80));
  25.       int y2 = int(y*80+map(imaginary, 0, 4, 0, 80));
  26.       while ((real*real+imaginary*imaginary) < 4 && (iterations < maxIterations)) {
  27.         float realTemp = real;
  28.         real = (real*real) - (imaginary*imaginary) + realConst;
  29.         imaginary = (2*realTemp*imaginary) + imaginaryConst;
  30.         stroke(color(map(iterations, 0, maxIterations, 0, 360), 100, 100));
  31.         int x3 = int(x*80+map(real, 0, 4, 0, 80));
  32.         int y3 = int(y*80+map(imaginary, 0, 4, 0, 80));
  33.         int x4 = int(x*80+map(nextReal(real, realConst, imaginary, imaginaryConst), 0, 4, 0, 80));
  34.         int y4 = int(y*80+map(nextImaginary(real, realConst, imaginary, imaginaryConst), 0, 4, 0, 80));
  35.         noFill();
  36.         curve(x1,y1,x2,y2,x3,y3,x4,y4);
  37.         //arc(float(x2), float(y2), float(x3), float(y3), angle(x2, y2, x3, y3), angle(x3,y3,x4,y4));
  38.         //line(x2,y2,x3,y3);
  39.         x1 = x2;
  40.         y1 = y2;
  41.         x2 = x3;
  42.         y2 = y3;
  43.        
  44.         //set2(int(x*80+map(real,0,4,0,80)),int(y*80+map(imaginary, 0,4,0,80)), color(map(iterations, 0, maxIterations, 0, 360), 100, 100), 1);
  45.         ++iterations;
  46.       }
  47.     }
  48.   }
  49. }
  50. float nextReal (float real, float realConst, float imaginary, float imaginaryConst) {
  51.   float realTemp = real;
  52.   real = (real*real) - (imaginary*imaginary) + realConst;
  53.   imaginary = (2*realTemp*imaginary) + imaginaryConst;
  54.   return real;
  55. }
  56. float nextImaginary (float real, float realConst, float imaginary, float imaginaryConst) {
  57.   float realTemp = real;
  58.   real = (real*real) - (imaginary*imaginary) + realConst;
  59.   imaginary = (2*realTemp*imaginary) + imaginaryConst;
  60.   return imaginary;
  61. }
  62. float angle(int cx, int cy, int ex, int ey) {
  63.   int dy = ey - cy;
  64.   int dx = ex - cx;
  65.   float theta = atan2(dy, dx); // range (-PI, PI]
  66.   return theta + PI;
  67. }
  68.  
  69. void set2 (int x, int y, color Color, int scale) {
  70.   for (int i=0; i!=scale; ++i) {
  71.     for (int i2=0; i2!=scale; ++i2) {
  72.       set(x*scale+i, y*scale+i2, Color);
  73.     };
  74.   };
  75. }
Advertisement
Add Comment
Please, Sign In to add comment