forked from: drawstar
...
@author lizhi
/**
* Copyright lizhi ( http://wonderfl.net/user/lizhi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4DEo
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.getTimer;
/**
* ...
* @author lizhi
*/
public class Test extends Sprite
{
private var shapes:Array = [];
public function Test()
{
addEventListener(Event.ENTER_FRAME, enterFrame);
stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_click);
}
private function stage_click(e:MouseEvent):void
{
var c:int = 3;
var color:uint = 0xffffff * Math.random();
while(c-->0){
var s:Shape3D = new Shape3D(Math.random()*1000,color);
addChild(s);
s.x = mouseX;
s.y = mouseY;
shapes.push(s);
}
}
private function enterFrame(e:Event):void
{
var t:Number = getTimer();
for (var i:int = shapes.length - 1; i >= 0;i-- ) {
var s:Shape3D = shapes[i];
s.update(t);
if (s.power<=0) {
shapes.splice(i, 1);
if (s.parent) {
s.parent.removeChild(s);
}
}
}
}
}
}
import flash.display.Shape;
import flash.geom.Point;
class Shape3D extends Shape {
private var id:int;
public var power:int = 100+50*Math.random();
private var vx:Number;
private var vy:Number;
private var rSpeed:Number = Math.random() / 300;
public function Shape3D(id:int,color:uint)
{
this.id = id;
graphics.beginFill(0);
var j:int = 16 * Math.random();
var r:Number = 10;
var minRP:Number = .5;
var minR:Number = r * minRP;
var num:int = 3+j/2;
var num2:int = num * 2;
var a:Number = Math.PI / num;
var a2:Number = a * 2;
var sa:Number = 0;
var isB:Boolean = j % 2 == 1;
var vs:Array = [];
for (var i:int = 0; i <= num2;i++ ) {
var ca:Number = i * a;
var cr:Number = (i % 2) == 0?r:minR;
var dx:Number = cr * Math.cos(ca)
var dy:Number = cr * Math.sin(ca);
if (i == 0) {
if(!isB)graphics.moveTo(dx, dy);
}else {
if (!isB) graphics.lineTo(dx, dy);
else vs.push(new Point(dx,dy));
}
}
if(isB){
vs = vs.concat(vs);
for (i = 0; i <= num2;i++ ) {
var p0:Point = vs[i];
var p1:Point = vs[i + 1];
var p01:Point = new Point((p0.x + p1.x) / 2, (p0.y + p1.y) / 2);
if (i==0) {
graphics.moveTo(p01.x, p01.y);
}else {
graphics.curveTo(p0.x, p0.y, p01.x, p01.y);
}
}
}
var speed:Number = 10*(.2 + Math.random());
var a3:Number = 2 * Math.PI * Math.random();
vx = Math.sin(a3) * speed;
vy = Math.cos(a3) * speed;
}
public function update(t:int):void
{
var ft:Number = id + t * rSpeed;
rotation = id + t * rSpeed;
scaleX = Math.sin(ft);
scaleY = Math.cos(ft);
power--;
alpha = power / 100;
vy += .1;
vx *= .95;
vy *= .95;
x += vx;
y += vy;
}
}