Paso 14: fractales
Este es un fractal interactivo: horizontal al mover el ratón sobre la imagen va a cambiar la profundidad de fractal.
Para experimentar la interactividad, seguir http://www.openprocessing.org/sketch/138956
Fórmula
WIDTH = 700; X_MIN = 0; X_MAX = 1; Y_MIN = 0; Y_MAX = 1; RATIO = AUTO; MOUSE_MOVE = true; // recursion // --------- int sierpinski(u, v, w, h, depth, maxdepth) { int val = ((int)(u/w * 3) % 2) * ((int)(v/h * 3) % 2); if(val==0 && depth<maxdepth) { return sierpinski((u*3 % w)/3, (v*3 % h)/3, w/3, h/3, depth+1, maxdepth); } else return val; } // start the computation and convert 0/1 to color // ---------------------------------------------- color rgb(x, y) { return color(sierpinski(x,y,X_SPAN,Y_SPAN, 1, maxdepth) * 255); } // redraw only on effective maxdepth change // ---------------------------------------- int maxdepth = -1; bool preDraw(t) { int d = (int)(mouseX/width*6) +1; bool doit = maxdepth!=d; maxdepth = d; return doit; }