dithering dots
THROW SLOWLY FOR BEST RESULTS.
// write as3 code here..
// write as3 code here..
//THROW SLOWLY FOR BEST RESULTS.
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
public class xm extends Sprite {
private var xxs:Array = new Array();
private var px:Array;
private var down:XX;
private var lx:Array;
private var tf:TextField = new TextField();
public function xm() {
init();
}
private function init():void {
var xx:XX = new XX();
xx.buttonMode = true;
xx.useHandCursor = true;
xxs.push(xx);
xx.x = xx.y = stage.stageWidth/2;
addChild(xx);
xx.addEventListener(MouseEvent.MOUSE_DOWN,this.onm);
tf.text = "Throw Me";
tf.selectable = false;
tf.setTextFormat(new TextFormat("Arial",14,0,true));
tf.autoSize = "left";
tf.x = (stage.stageWidth/2)-(tf.width/2);
tf.y = xx.y-60;
addChild(tf);
var xt:TextField = new TextField();
xt.selectable = false;
xt.autoSize = "left";
xt.text = "JOSHSTRIKE.COM";
xt.setTextFormat(new TextFormat("Arial",10,0,true));
xt.x = stage.stageWidth-xt.width-10;
xt.y = stage.stageHeight-xt.height-3;
addChild(xt);
}
private function onm(evt:MouseEvent):void {
if (evt.type == "mouseDown") {
this.contains(tf) ? removeChild(tf) : void;
down = evt.currentTarget as XX;
evt.currentTarget.vel = [mouseX-evt.currentTarget.x,mouseY-evt.currentTarget.y];
px = [this.mouseX-evt.currentTarget.x,this.mouseY-evt.currentTarget.y];
stage.addEventListener(Event.ENTER_FRAME,loop,false,0,true);
stage.addEventListener(MouseEvent.MOUSE_UP,onm);
} else {
down = null;
}
}
private function loop(evt:Event):void {
var topush:Array = new Array();
if (xxs.length<1) {
init();
return (void);
}
for each (var xx:XX in xxs) {
if (down == xx) {
if (mouseX<0 || mouseX>stage.stageWidth || mouseY<0 || mouseY>stage.stageWidth) {
down = null;
return (void);
}
var ww:Array = [xx.x,xx.y];
xx.x = mouseX-px[0];
xx.y = mouseY-px[1];
xx.vel = [ww[0]-xx.x,ww[1]-xx.y];
} else {
xx.x -= xx.vel[0]/3;
xx.y -= xx.vel[1]/3;
var xlx:Array = [xx.vel[0],xx.vel[1]];
xx.vel[0] *= (xx.x < 0 || xx.x > stage.stageWidth) ? -1 : 1;
xx.vel[1] *= (xx.y < 0 || xx.y > stage.stageHeight) ? -1 : 1;
if (!xx.split && (xx.vel[0] != xlx[0] || xx.vel[1] != xlx[1])) {
if (!xx.halve()) {
this.contains(xx) ? removeChild(xx) : void;
xxs.splice(xxs.indexOf(xx),1);
continue;
}
var nex:XX = new XX(xx.wid,xx.vel);
nex.x = xx.x;
nex.y = xx.y;
nex.split = true;
nex.vel[xlx[0] == nex.vel[0] ? 0 : 1]*=-1;
nex.split = true;
topush.push(nex);
addChild(nex);
} else {
xx.split = false;
}
}
}
for each (var t:XX in topush) {
xxs.push(t);
}
}
}
}
import flash.display.Sprite;
internal class XX extends Sprite {
public var split:Boolean = false;
public var wid:Number;
public var vel:Array = new Array();
public function XX(wid:Number = 40,vel:Array = null) {
this.vel = vel ? [vel[0],vel[1]] : [0,0];
this.wid = wid;
drawme();
}
private function drawme():void {
graphics.clear();
graphics.beginFill(0,1);
graphics.drawCircle(0,0,wid);
graphics.endFill();
}
public function halve():Boolean {
if (wid<2) {
return false;
}
wid/=1.3;
drawme();
return true;
}
}