はじめてのFrocessing
/////////////////////////////////////
はじめてFrocessingに手を出してみる。
Frocessingっぽいコードになってない気もするが
そこはご愛敬で。
リヴィジョンの違いか、wonderflではsetupを実行してくれないの?
////////////////////////////////////
///////////////////////////////////////
//はじめてFrocessingに手を出してみる。
//Frocessingっぽいコードになってない気もするが
//そこはご愛敬で。
// リヴィジョンの違いか、wonderflではsetupを実行してくれないの?
//
//////////////////////////////////////
package
{
import flash.text.TextField;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.display.StageQuality;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.utils.getTimer;
import flash.utils.getQualifiedClassName;
import frocessing.display.F5MovieClip;
[SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="0")]
public class FrocessingDemo extends F5MovieClip
{
private var output:TextField;
private var pts:Array;
public function FrocessingDemo()
{
initOutput();
println('Construct ' + getQualifiedClassName(this));
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(e:Event):void
{
removeEventListener(e.type, arguments.callee);
setup();
}
public function setup():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.LOW;
size(stage.stageWidth, stage.stageHeight);
pts = new Array(20 * 100);
for ( var i:int = 0; i < pts.length; i++) {
pts[i] = new P(i / 5000.0, width * 0.5, height * 0.5);
}
}
public function draw():void {
noStroke();
fill(0, 64, 127);
rect(0, 0, width, height);
stroke(127, 255, 127);
for (var i:int = 0; i < pts.length; i++) {
update(pts[i]);
}
}
public function update(p:P):void {
var mx:Number = mouseX + 1;//0除算の回避
var my:Number = mouseY + 1;
p.id += 0.01;
p.d = (noise(p.id, p.x/mx, p.y/my) - 0.5) * mx;
p.x += Math.cos(radians(p.d)) * p.s;
p.y += Math.sin(radians(p.d)) * p.s;
if (p.x < -10) p.x = p.xp = width + 10;
if (p.x > width + 10) p.x = p.xp = -10;
if (p.y < -10) p.y = p.yp = height + 10;
if (p.y > height + 10) p.y = p.yp = -10;
line(p.xp, p.yp, p.x, p.y);
p.xp = p.x;
p.yp = p.y;
}
////////////////
// 出力
///////////////
private function initOutput():void {
var margin:Number = 10;
addChild(output = new TextField());
output.selectable = false;
output.multiline = true;
output.width = stage.stageWidth - margin * 2;
output.height = stage.stageHeight - margin * 2;
}
public function print(... args):void {
output.appendText(args.join(", "));
}
public function println(... args):void {
output.appendText(args.join(", "));
output.appendText("\n");
}
}
}
import frocessing.math.FMath;
class P {
public var id:Number;
public var x:Number;
public var y:Number;
public var xp:Number;
public var yp:Number;
public var s:Number;
public var d:Number;
public function P(id:Number, x:Number, y:Number) {
this.id = id;
this.x = this.xp = x;
this.y = this.yp = y;
s = FMath.random(2, 7);
}
}