Strange Attractor in 6 lines

Caught up in 25-line fever, I started hacking away at a Strange attractor generator and got it down to 6 lines. 🙂

[as]var bmp:Bitmap = addChild(new Bitmap(new BitmapData(800, 800, false, 0xffffff))) as Bitmap;
for(var i:int = 0; i < 12; i++) this["a" + (i + 1)] = (("VBWNBDELYHUL").charCodeAt(i) - 77) / 10; var p:Point = new Point(.1, .1); for(i = 0; i < 10000; i++) { p = new Point(this["a" + 1] + this["a" + 2] * p.x + this["a" + 3] * p.x * p.x + this["a" + 4] * p.x * p.y + this["a" + 5] * p.y + this["a" + 6] * p.y * p.y, this["a" + 7] + this["a" + 8] * p.x + this["a" + 9] * p.x * p.x + this["a" + 10] * p.x * p.y + this["a" + 11] * p.y + this["a" + 12] * p.y * p.y); bmp.bitmapData.setPixel(400 + p.x * 100, 400 - p.y * 100, 0); // 400, 400 is center. 100 is scale. } [/as] Should give you something like this:

From http://mathworld.wolfram.com/StrangeAttractor.html

The seed is the 12-character string in the second line. Valid chars are A-Y. Other seeds to try:

“VBWNBDELYHUL”, “AMTMNQQXUYGA”, “CVQKGHQTPHTE”, “FIRCDERRPVLD”, “GIIETPIQRRUL”, “GLXOESFTTPSV”, “GXQSNSKEECTX”, “HGUHDPHNSGOH”

All from the above link, where you can find even more, or try to discover your own (not so easy).

Coulda gotten rid of the seed and hard coded the parameters right into line 5, allowing me to do away with line 2 all together, but then it would be pretty useless.

This entry was posted in ActionScript, Flash. Bookmark the permalink.

8 Responses to Strange Attractor in 6 lines

  1. ynk says:

    5 lines :p ?

    var bmp:Bitmap = addChild(new Bitmap(new BitmapData(800, 800, false, 0xffffff))) as Bitmap, p:Point = new Point(.1, .1);

  2. m says:

    Also, could you move line 5 after the {? One line less:P

  3. mark says:

    Hey look at my 1 line of code!

    something( something( something (something( something()))))

    bit of a cop out really

  4. Pixelero says:

    ??? 3 lines by first using ynk’s idea and then writing the whole loop on one line ???

    for(i = 0; i <10000; i++) bmp.bitmapData.setPixel(400 + (p = new Point(this[“a” + 1] + this[“a” + 2] * p.x … ).x * 100, 400 – p.y * 100, 0);

    … I didn’t test

  5. rdjman says:

    Got inspired by this and created a simple file that randomly generates seeds and also draws lines between the dots to create an interesting effect. You can check it out here:

    http://star-frost.com/projects/flash/strange%20attractors.html

    Maybe jonathanpace can add lines and random seeds to his application and it would be cool for exploring strange attractors. They’re definitely interesting to look at.

  6. cool .. I’ll have to try playing around with strange attractors sometime. The most beautiful ones I’ve seen are here

    http://local.wasp.uwa.edu.au/~pbourke/fractals/clifford/

  7. Matt says:

    try the word nonelectrics :O

Leave a Reply