Gumowski / Mira

Actionscript:
  1. [SWF(width = 600, height = 600)]
  2. var a:Number = 0.02;
  3. var b:Number = .9998;
  4.  
  5. var xn1:Number = 5;
  6. var yn1:Number = 0;
  7. var xn:Number, yn:Number;
  8.  
  9. var scale:Number = 10;
  10. var iterations:Number = 20000;
  11.  
  12. function f(x:Number):Number{
  13.     var x2:Number = x * x;
  14.     return a * x + (2 * (1 - a) * x2) / (1 + x2);
  15. }
  16.  
  17. var canvas:BitmapData = Bitmap(addChild(new Bitmap(new BitmapData(600,600,false,0xEFEFEF)))).bitmapData;
  18.                                                                        
  19. addEventListener(Event.ENTER_FRAME, onLoop);
  20. function onLoop(evt:Event):void {
  21.    
  22.     canvas.fillRect(canvas.rect, 0xEFEFEF);
  23.     a = mouseY / 1000;
  24.     xn1 = mouseX / 30;
  25.     yn1 = 0;
  26.     for (var i:int = 0; i<iterations; i++){
  27.           xn = xn1;
  28.           yn = yn1;
  29.          
  30.           xn1 = b * yn + f(xn);
  31.           yn1 =  -xn + f(xn1);
  32.           canvas.setPixel( 280 + xn1 * scale, 300 + yn1 * scale, 0x000000);
  33.     }
  34. }

Notice the setup for this is very similar to yesterdays flames attractor post.

Back in october of last year I stumbled upon the excellent subblue website by Tom Beddard. I was REALLY impressed by a blog post about Gumowski / Mira patterns. If you haven't seen it you should go take a look.

I'd never heard of Gumowski / Mira patterns before and made a mental note to go and try to read about them and maybe find an equation to port to actionscript or processing. Anyway, a few days ago I decided to go ahead and look up the math and... this is the result.

I got equation over at mathworld...

For simplicity I intentionally made the actionscript code look as much like the mathworld equation as possible. Using f for my function name and using xn1, yn1 etc... There are a few speed optimizations that could be made but I wanted this snippet to be very readable.

Here are a few examples of what this code will generate:

This entry was posted in Math, 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 *

*
*