BIT-101 [2003-2017]

Emergent Behavior


I wanted to make a demonstration file for a talk I’m doing this week to show the difference between bitmap and vector performance. So I needed something that drew a whole lot of lines. Came up with this, which I probably won’t use for the presentation, but surprised me with a cool pattern emerging.

[kml_flashembed publishmethod=“static” fversion=“10.0.0″ movie=“https://www.bit-101.com/2003/wp-content/uploads/2010/01/speed_test_vector.swf” width=“400″ height=“400″ targetclass=“flashmovie”]

Get Adobe Flash player

[/kml_flashembed]

Click to change the pattern. Zoom in once or twice to see what’s actually happening. Here’s the code:

[as3]var angle:Number = 0;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.CLICK, onClick);

var size:Number = 5;
var xrand:Number = Math.random() * .1 – .05;
var yrand:Number = Math.random() * .1 – .05;

function onEnterFrame(event:Event):void
{
graphics.clear();
graphics.lineStyle(0, 0, 1);

for(var i:int = size; i < 400; i+= size) { for(var j:int = size; j < 400; j+= size) { var xoff:Number = Math.cos(angle + Math.cos(i * xrand)) * size; var yoff:Number = Math.sin(angle + Math.sin(j * yrand)) * size; graphics.moveTo(i, j); graphics.lineTo(i + xoff, j + yoff); } } angle += .1; } function onClick(event:MouseEvent):void { xrand = Math.random() * .12 - .06; yrand = Math.random() * .12 - .06; }[/as3]

« Previous Post
Next Post »