初めてのFrocessing-3:合体 forked from: 初めてのFrocessing-2:curveVertex
// forked from szktkhr's 初めてのFrocessing-2:curveVertex
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
[SWF(width="465", height="465", frameRate="60", backgroundColor="#000000")]
public class Sketch extends Sprite {
private var movement1:Movement;
private var movement2:Movement;
private var movement3:Movement;
private var movement4:Movement;
private var movement5:Movement;
private var lines:Array;
private var brown:Point;
private var c:uint = 0;
public function Sketch() {
addEventListener(Event.ADDED_TO_STAGE, initialize);
}
private function initialize(e:Event):void {
// movement
brown = new Point(stage.stageWidth / 2, stage.stageHeight / 2);
movement1 = new Movement(brown);
addChild(movement1);
movement2 = new Movement(brown);
addChild(movement2);
movement3 = new Movement(brown);
addChild(movement3);
movement4 = new Movement(brown);
addChild(movement4);
movement5 = new Movement(brown);
addChild(movement5);
// lines
lines = [];
addEventListener(Event.ENTER_FRAME, draw);
var l:Line = new Line(stage.stageWidth, movement1, movement2, movement3, movement4, movement5);
lines.push(l);
addChild(l);
}
public function draw(e:Event):void {
if (++c % 1 !== 0) return;
gogoBrown();
var prevLine:Line = lines[lines.length - 1];
var l:Line = new Line(stage.stageWidth, movement1, movement2, movement3, movement4, movement5);
lines.push(l);
addChild(l);
l.start();
}
public function remove(l:Line):void {
removeChild(l);
}
public function gogoBrown():void {
brown.x += Math.random() * 2 > 1? (Math.random() * 10): -(Math.random() * 10);
brown.y += Math.random() * 2 > 1? (Math.random() * 10): -(Math.random() * 10);
if (brown.x < 0 || brown.x > stage.stageWidth) brown.x = Math.random() * stage.stageWidth;
if (brown.y < 0 || brown.y > stage.stageHeight) brown.y = Math.random() * stage.stageHeight;
}
}
}
import flash.geom.Point;
import caurina.transitions.Tweener;
import frocessing.display.F5MovieClip2D;
class Movement extends F5MovieClip2D {
private var vx:Number = 0;
private var vy:Number = 0;
private var brown:Point;
private var vs:Number;
public function Movement(b:Point) {
brown = b;
x = Math.random() * 450;
y = Math.random() * 450;
vs = Math.random() * 500 + 200;
}
public function draw():void {
// noStroke();
// fill(255);
// circle(0, 0, 10);
vx += (brown.x - x) / vs;
vy += (brown.y - y) / vs;
vx /= 1.005;
vy /= 1.005;
x += vx / 1;
y += vy / 1;
}
}
class Line extends F5MovieClip2D {
private var movement1:Movement;
private var movement2:Movement;
private var movement3:Movement;
private var movementStart:Movement;
private var movementEnd:Movement;
public function Line(w:Number, m1:Movement, m2:Movement, m3:Movement, ms:Movement, me:Movement) {
movement1 = m1;
movement2 = m2;
movement3 = m3;
movementStart = ms;
movementEnd = me;
}
public function start():void {
noFill();
stroke(255);
beginShape();
curveVertex(0, stage.stageHeight / 2);
curveVertex(0, stage.stageHeight / 2);
// curveVertex(movementStart.x, movementStart.y);
// curveVertex(movement1.x, movement1.y);
// curveVertex(movement2.x, movement2.y);
// curveVertex(movement3.x, movement3.y);
curveVertex(movementEnd.x, movementEnd.y);
curveVertex(stage.stageWidth, stage.stageHeight / 2);
curveVertex(stage.stageWidth, stage.stageHeight / 2);
endShape();
Tweener.addTween(this, {y: stage.stageHeight * 1.5, alpha: 0, time: 3.5, transition: 'easeInBack', onComplete: function():void {
var p:Sketch = parent as Sketch;
p.remove(this);
}});
}
}