Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float maxImaginary = 2;
- void setup () {
- colorMode(HSB, 360, 100, 100);
- size(8000, 8000);
- fill(0);
- rect(0,0,width,height);
- mandelbrot();
- }
- void draw () {
- }
- void mandelbrot () {
- int maxIterations = 500;
- for (int x=0; x!=height/80; ++x) {
- for (int y=0; y!=width/80; ++y) {
- float real = map(x, 0, width/80, minReal, maxReal);
- float realConst = real;
- float imaginary = map(y, 0, height/80, minImaginary, maxImaginary);
- float imaginaryConst = imaginary;
- int iterations = 0;
- int x1 = int(x*80+map(real, 0, 4, 0, 80));
- int y1 = int(y*80+map(imaginary, 0, 4, 0, 80));
- int x2 = int(x*80+map(real, 0, 4, 0, 80));
- int y2 = int(y*80+map(imaginary, 0, 4, 0, 80));
- while ((real*real+imaginary*imaginary) < 4 && (iterations < maxIterations)) {
- float realTemp = real;
- real = (real*real) - (imaginary*imaginary) + realConst;
- imaginary = (2*realTemp*imaginary) + imaginaryConst;
- stroke(color(map(iterations, 0, maxIterations, 0, 360), 100, 100));
- int x3 = int(x*80+map(real, 0, 4, 0, 80));
- int y3 = int(y*80+map(imaginary, 0, 4, 0, 80));
- int x4 = int(x*80+map(nextReal(real, realConst, imaginary, imaginaryConst), 0, 4, 0, 80));
- int y4 = int(y*80+map(nextImaginary(real, realConst, imaginary, imaginaryConst), 0, 4, 0, 80));
- noFill();
- curve(x1,y1,x2,y2,x3,y3,x4,y4);
- //arc(float(x2), float(y2), float(x3), float(y3), angle(x2, y2, x3, y3), angle(x3,y3,x4,y4));
- //line(x2,y2,x3,y3);
- x1 = x2;
- y1 = y2;
- x2 = x3;
- y2 = y3;
- //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);
- ++iterations;
- }
- }
- }
- }
- float nextReal (float real, float realConst, float imaginary, float imaginaryConst) {
- float realTemp = real;
- real = (real*real) - (imaginary*imaginary) + realConst;
- imaginary = (2*realTemp*imaginary) + imaginaryConst;
- return real;
- }
- float nextImaginary (float real, float realConst, float imaginary, float imaginaryConst) {
- float realTemp = real;
- real = (real*real) - (imaginary*imaginary) + realConst;
- imaginary = (2*realTemp*imaginary) + imaginaryConst;
- return imaginary;
- }
- float angle(int cx, int cy, int ex, int ey) {
- int dy = ey - cy;
- int dx = ex - cx;
- float theta = atan2(dy, dx); // range (-PI, PI]
- return theta + PI;
- }
- void set2 (int x, int y, color Color, int scale) {
- for (int i=0; i!=scale; ++i) {
- for (int i2=0; i2!=scale; ++i2) {
- set(x*scale+i, y*scale+i2, Color);
- };
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment