/* Failed Fractals: a code poem Jose Carlos Silvestre, 2008 */ PImage img; int radius = 1500000; int c_rel = 1; int c_ima = 1; int x, y; int turn = 0; void setup() { size(600, 600); } void draw() { background(255,255,255); img = createImage(600, 600, ARGB); for(int i=0; i < img.pixels.length; i++) { x = (i % img.width)*2; y = (i/img.width)*2; int cor = 0; int r = 0; while(cor < 6 && r < radius) { int x2 = x*x - y*y + c_rel; int y2 = 2*x*y + c_ima; cor++; r = x2*x2 + y2*y2; if (r > radius) { break;} else {x = x2; y = y2;} } switch(cor) { case 1: img.pixels[i] = color(0, 0, 0); break; case 2: img.pixels[i] = color(100, 100, 100); break; case 3: img.pixels[i] = color(130, 130, 130); break; case 4: img.pixels[i] = color(170, 170, 170); break; case 5: img.pixels[i] = color(200, 200, 200); break; case 6: img.pixels[i] = color(220, 220, 220); break; } } image(img, 0, 0); // this part varies the parameter c to create // the animation. it watches for c itself to // overflow to switch turns. switch(turn) { case 0: if(c_rel > 0) c_rel*=2; else {c_rel=-1; turn=1;} break; case 1: if(c_rel <0) c_rel*=2; else {c_rel=1; turn=2;} break; case 2: if(c_ima > 0) c_ima*=2; else {c_ima=-1; turn=3;} break; case 3: if(c_ima <0) c_ima*=2; else {c_ima=1; turn=4;} break; case 4: if(c_ima > 0 && c_rel > 0) {c_rel*=2; c_ima*=2;} else {c_ima=-1; c_rel=1; turn=5;} break; case 5: if(c_ima < 0 && c_rel > 0) {c_rel*=2; c_ima*=2;} else {c_ima=1; c_rel=1; turn=6;} break; case 6: if(c_ima > 0 && c_rel > 0) {c_rel*=3; c_ima*=2;} else {c_ima=1; c_rel=1; turn=7;} break; case 7: if(c_ima > 0 && c_rel > 0) {c_rel*=2; c_ima*=3;} else {c_ima=1; c_rel=1; turn=8;} break; case 8: if(c_ima > 0 && c_rel > 0) {c_rel*=15; c_ima*=2;} else {c_ima=1; c_rel=1; turn=9;} break; case 9: turn = 0; noLoop(); break; } delay(150); } void mousePressed() { loop(); }