forked from: Cloth balls
// forked from spikything's Cloth balls
package {
import flash.display.Sprite;
import flash.events.Event;
[SWF(backgroundColor=0)]
public class Main extends Sprite {
private var sprites:Array;
private var gridsize:int = 40;
private var spacing:Number = 5;
private var amplitude:Number = 6;
private var frequency:Number;
private var phase:Number = 0;
private var ticker:int = 0;
public function Main() {
sprites = new Array();
var sprite:Sprite;
for (var i:int = 0; i < gridsize; i++) {
sprites[i] = new Array();
for (var j:int = 0; j < gridsize; j++) {
sprite = new Sprite();
//sprite.cacheAsBitmap = true;
sprite.graphics.beginFill(0x666666);
sprite.graphics.drawCircle(0, 0, 4);
sprite.graphics.endFill();
sprite.graphics.beginFill(0x999999);
sprite.graphics.drawCircle(-1, -1, 3);
sprite.graphics.endFill();
sprite.graphics.beginFill(0xffffff);
sprite.graphics.drawCircle(-2, -2, 1);
sprite.graphics.endFill();
sprites[i][j] = sprite;
addChild(sprite);
}
}
addEventListener(Event.ENTER_FRAME, update);
}
private function update(e:Event):void {
ticker++;
phase = ticker * .7;
frequency = .2 + Math.sin(ticker/50)/20;
var sprite:Sprite;
var offset:Number;
var sini:Number;
for (var i:int = 0; i < gridsize; i++) {
sini = Math.sin((i + phase) * frequency);
for (var j:int = 0; j < gridsize; j++) {
sprite = sprites[i][j] as Sprite;
offset = sini * amplitude + Math.cos((j+phase)*frequency) * amplitude;
sprite.x = 220 + i*spacing - j*spacing;
sprite.y = 50 + j*spacing*.5 + i*spacing*.5 + offset;
}
}
}
}
}