/* todo: clicking creates a box that you can resize to fit the new area you want to render. google maps style navigation */ float mandelbrot_maxx = 2; float mandelbrot_minx = -2; float mandelbrot_maxy = 2; float mandelbrot_miny = -2; int mandelbrot_threshhold = 2; int mandelbrot_tmax = 1000; float HUE_SHIFT = 0; float HUE_INNER = 0.5; float HUE_OUTER = 0.75; float HUE_SCALE = 2; void setup() { size(400, 400); colorMode(HSB,1.0); doMandelbrot(); print("Done"); } void doMandelbrot(){ float[] c = new float[2]; float[] d = new float[2]; int t; float mandelbrot_width = mandelbrot_maxx - mandelbrot_minx; float mandelbrot_height = mandelbrot_maxy - mandelbrot_miny; loadPixels(); // a and b vary from -500 to 500 for(int a = 0; a < height; a += 1) { for(int b = 0; b < width; b += 1) { // Create complex c to represent a point on the picture c[1] = map(a, 0, height, mandelbrot_miny, mandelbrot_maxy); c[0] = map(b, 0, width, mandelbrot_minx, mandelbrot_maxx); // Initiate our x to 0 d[0] = 0; d[1] = 0; for(t = 1; t <= mandelbrot_tmax; t++) { d = complex_add(complex_mult(d, d), c); if(complex_abs(d) > mandelbrot_threshhold) break; } if (t < mandelbrot_tmax) { float mcolor = constrain((t/(float)mandelbrot_tmax) * HUE_SCALE, 0, 1); mcolor += HUE_SHIFT; map(mcolor, 0, 1, HUE_OUTER, HUE_INNER); if (mcolor > 1){ mcolor--; } pixels[a*width+b] = color(mcolor,1,1); //set(a, b, color(mcolor,1,1)); } else { pixels[a*width+b] = color(0,0,0); //set(a, b, color(0, 0, 0)); } } } updatePixels(); } float[] complex_add(float[] m, float[] n) { float[] r = new float[2]; r[0] = m[0]+n[0]; r[1] = m[1]+n[1]; return r; } float[] complex_mult(float[] m, float[] n) { float[] r = new float[2]; r[0] = m[0]*n[0] - m[1]*n[1]; r[1] = m[0]*n[1] + m[1]*n[0]; return r; } float complex_abs(float[] m) { float r; r = sqrt((m[0])*(m[0]) + (m[1])*(m[1])); return r; } boolean firstclick = true; int firstX, firstY; void mouseClicked() { if (firstclick) { firstX = mouseX; firstY = mouseY; firstclick = !firstclick; } else { float minx = map(firstX, 0, width, mandelbrot_minx, mandelbrot_maxx); float maxx = map(mouseX, 0, width, mandelbrot_minx, mandelbrot_maxx); mandelbrot_minx = minx; mandelbrot_maxx = maxx; float miny = map(firstY, 0, width, mandelbrot_miny, mandelbrot_maxy); float maxy = miny + maxx-minx; mandelbrot_miny = miny; mandelbrot_maxy = maxy; print("New Bounds\nfloat mandelbrot_minx = "+minx+";\nfloat mandelbrot_maxx = "+maxx+";\nfloat mandelbrot_miny = "+miny+";\nfloat mandelbrot_maxy = "+maxy+";\n"); doMandelbrot(); firstclick = !firstclick; } } void draw() { }