flash on 2011-3-11

by George.Profenza
♥0 | Line 58 | Modified 2011-05-25 20:15:25 | MIT License
play

ActionScript3 source code

/**
 * Copyright George.Profenza ( http://wonderfl.net/user/George.Profenza )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mlC8
 */

package {
    import flash.display.Sprite;
    import frocessing.display.F5MovieClip2D;
    public class FlashTest extends F5MovieClip2D {
        
        private var points:Array;
        private var pointsNum:int;
        
        public function FlashTest() {
            size(550,400);
            smooth();
            strokeWeight(.5);
            background(255);
            noFill();
            trace('flash test');
        }
        public function setPoints():void{
            trace('set points');
          stroke(int(random(255)));
          points = new Array();
          pointsNum = int(random(3,27));
          var vel:Number = random(PI);
          for(var i:int = 0; i < pointsNum; i++) points.push(new Point(random(0,width),random(0,height),random(-vel,vel),random(-vel,vel)));
          trace(points,points.length);
        }
        public function draw():void{
          beginShape(LINES);
          for(var i:int = 0; i < pointsNum; i++){
              points[i].update();
              vertex(points[i].rx,points[i].ry);
          }
          endShape();
        }
        public function mousePressed():void{
          background(255);
          setPoints();
        }
    }
}
import frocessing.display.F5MovieClip2D;
internal class Point extends F5MovieClip2D {
      internal var _x:Number,_y:Number,vx:Number,vy:Number,va:Number,a:Number,r:Number,rx:Number,ry:Number;
      public function Point(x:Number,y:Number,vx:Number,vy:Number){
        this._x = x;
        this._y = y;
        this.vx = vx;
        this.vy = vy;
        r = random(vy);
        va = random(vx);
      }
      public function update():void{
        _x += vx;
        _y += vy;
        if(_x < 0 || _x > width) vx *= -1;
        if(_y < 0 || _y > height) vy *= -1;
        a += va;
        rx = _x + cos(a) * r;
        ry = _y + sin(a) * r;
      }
  } 
/*
ArrayList points;
int pointsNum;
void setup(){
  size(550,400,P2D);
  smooth();
  strokeWeight(.5);
  background(255);
  noFill();
  setPoints();  
}
void setPoints(){
  stroke((int)random(255),20);
  points = new ArrayList();
  pointsNum = (int)random(3,27);
  float vel = random(PI);
  for(int i = 0; i < pointsNum; i++) points.add(new Point(random(0,width),random(0,height),random(-vel,vel),random(-vel,vel)));
}
void draw(){
  beginShape();
  for(int i = 0; i < pointsNum; i++){
      Point p = (Point)points.get(i);
      p.update();
      vertex(p.rx,p.ry);
  }
  endShape();
}
void mousePressed(){
  background(255);
  setPoints();
}
class Point{
  float x,y,vx,vy,va,a,r,rx,ry;
  Point(float x,float y,float vx,float vy){
    this.x = x;
    this.y = y;
    this.vx = vx;
    this.vy = vy;
    r = random(vy);
    va = random(vx);
  }
  void update(){
    x += vx;
    y += vy;
    if(x < 0 || x > width) vx *= -1;
    if(y < 0 || y > height) vy *= -1;
    a += va;
    rx = x + cos(a) * r;
    ry = y + sin(a) * r;
  }
}
*/