Nov 12
En este ejemplo la idea es generar un algoritmo que represente el conjunto de Mandelbrot. La representación gráfica de ésto, es ni más ni menos que uno de los gráficos fractales mas conocidos y utilizados. Alterando los coeficientes de la fórmula, es bastante sencillo ver en detalle el gráfico, digamos, hacia el infinito.
La interpolación de color es bastante sencilla. Les dejo el ejemplo, y quiero destacar que el algoritmo tiene una gran cantidad de transcripciones a otros lenguajes; este en particular es una adaptación de uno que vi en C++.
Source CODE: fract.zip
This movie requires Flash Player 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import flash.display.BitmapData; var myBitmapData:BitmapData = new BitmapData(Stage.width, Stage.height, false, 0x0ffffff); var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth()); mc._alpha=0 mc.attachBitmap(myBitmapData,this.getNextHighestDepth()); ///Limites horizontales y verticales Maxx = 1; Minx = -2 Maxy = 1.5; Miny = -1.5; initer = 100;//Numero de iteraciones, a mayor valor, mas detalle i = 0;//Var para el loop j = 0;//Idem scrsizex = Stage.width;//Tamaño de pantalla scrsizey = Stage.height;//IDEM pixcorx = (Maxx-Minx)/scrsizex;//ESCALA pixcory = (Maxy-Miny)/scrsizey;//IDEM function mandel(xpt, ypt) { x = 0; y = 0; xnew = 0; ynew = 0; for (k=0; k<=initer; k++) { xnew = x*x-y*y+xpt*pixcorx+Minx ynew = (2*x*y+Maxy-ypt*pixcory); x = xnew; y = ynew; if ((x*x+y*y)>4) { break; } } color = k; if (k>=initer) { myBitmapData.setPixel(xpt,ypt,parseInt("0xFFFFFF")); } else { miColor = Number(255-(Math.abs(Math.cos((color*color)/180*Math.PI)*Math.sin((color*color)/180*Math.PI)*255))).toString(16); if (String(miColor).length<2) { miColor = "0"+miColor; } miRgb = "0xff"+miColor+miColor myBitmapData.setPixel(xpt,ypt,parseInt(miRgb)); } } function imprime() { for (r=0; r<=50; r++) { if (i<Stage.width) { if (j<Stage.height) { mandel(i,j); j += 1; } else { j = 0; i += 1; } } else { clearInterval(idInt); } } } stop(); |
One Response to “Gráficos Fractales y Flash, Mandelbrot ataca CPU”
Leave a Reply
You must be logged in to post a comment.

December 8th, 2007 at 3:24 am
[…] to see differents pics from the Mandelbrot Set (one of the most commons sets in Fractals). LINK: http://alejandroquarto.com/2007/11/12/graficos-fractales-y-flash-mandelbrot-ataca-cpu/ This example is possible the best one. If you like game development, im sure you played some good […]