/* Failed Fractals: a code poem Jose Carlos Silvestre, 2008 Navigational version */ PImage img; int radius = 1500000; int c_rel = 1; int c_ima = 1; int incremento = 1; int x, y; int turn = 0; int click = 0; int isLoop = 1; int zoom = 6; int centrox = 0; int centroy = 0; boolean animation = false; boolean clicked = false; boolean navigation = false; void setup() { size(800, 500); loop(); } void draw() { background(255,255,255); img = createImage(800, 500, ARGB); for(int i=0; i < img.pixels.length; i++) { x = zoom*((i % img.width) - int(img.width/2)) + centrox; y = zoom*((i/img.width) - int(img.height/2)) + centroy; 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+=incremento; r = x2*x2 + y2*y2; if (r > radius) { break;} else {x = x2; y = y2;} } if(cor==1) img.pixels[i] = color(0, 0, 0); else img.pixels[i] = color(((float)cor)*100/6 + 100,((float)cor)*100/6 + 100,((float)cor)*100/6 + 100); } image(img, 0, 0); if(animation) { // 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() { navigation = true; animation = true; } void keyPressed() { if (key == CODED) { if (keyCode == UP) centroy -= zoom*10; else if (keyCode == DOWN) centroy += zoom*10; else if (keyCode == RIGHT) centrox += zoom*10; else if (keyCode == LEFT) centrox -= zoom*10; } if (key == ' ') { animation = !animation;} if (key == 'z') {if(zoom>1) zoom--;} if (key == 'x') {if(zoom < 15) zoom++;} }