Random Equation Attractor

Actionscript:
  1. [SWF(width = 800, height = 800)]
  2. var a:Number = 0.19;
  3. var b:Number = .9;
  4. var c:Number = 1.3
  5. var xn1:Number = 5;
  6. var yn1:Number = 0;
  7. var xn:Number, yn:Number;
  8.  
  9. var scale:Number =40;
  10. var iterations:Number = 20000;
  11.  
  12. function f(x:Number):Number{
  13.     // too lazy to simplify this at the moment
  14.     return((x + .1 + x * (a - c) * x) / (1.1 + a * (c*c + a*a)  * x * x )) * 1.3;
  15. }
  16.  
  17. var canvas:BitmapData = Bitmap(addChild(new Bitmap(new BitmapData(800,800,false,0xEFEFEF)))).bitmapData;
  18.                                                                        
  19. addEventListener(Event.ENTER_FRAME, onLoop);
  20. function onLoop(evt:Event):void {
  21.    
  22.     canvas.fillRect(canvas.rect, 0xEFEFEF);
  23.      
  24.     c +=  ((stage.stageWidth/2 - mouseX) / 8000 - c) / 2;
  25.    
  26.     xn1 = 0;
  27.     yn1 = 0;
  28.     for (var i:int = 0; i<iterations; i++){
  29.           xn = xn1;
  30.           yn = yn1;
  31.          
  32.           xn1 = -xn - a + c +  f(yn);
  33.           yn1 = -xn + c * f(xn * yn);
  34.           canvas.setPixel( 380 + xn1 * scale, 450 + yn1 * scale, 0x000000);
  35.     }
  36. }

I was randomly messing around with strange attractors a few weeks back and this is one of the better results.... I arbitrarily altered equations until I got a nice result. You can move your mouse left and right to alter some of the params. Here is what it looks like when your mouse is in the middle of the screen:

This entry was posted in BitmapData, misc, motion, pixel manipulation, setPixel and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*