forked from shwang/VectorFieldsStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.as
63 lines (51 loc) · 1.3 KB
/
Main.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package {
import flash.display.*;
import flash.events.*;
import flash.ui.*;
public class Main extends Sprite {
private var started:Boolean = false;
private var paused:Boolean = false;
private var particles:Array = [];
public function Main() {
start();
}
public function start():void {
populateParticles();
addEventListener(Event.ENTER_FRAME, step);
Registry.stage.addEventListener(MouseEvent.CLICK, mouseClick);
Registry.stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
}
private function populateParticles():void {
var i:uint = 0;
do {
particles[i] = Particle.rand(Registry.DEFAULT_RANGE);
} while(++i < Registry.DEFAULT_POPULATION)
}
public function end():void {
started = false;
particles = [];
}
public function reset():void {
if (started) end();
start();
}
public function step(evt:Event = null):void {
if (paused) return;
graphics.clear();
var i:int = -1;
while(++i < particles.length) {
var e:Particle = particles[i];
e.update();
e.draw(graphics);
}
//paused = true;
}
public function mouseClick(evt:Event = null):void {
//trace("click");
++Registry.vfSelection;
Registry.vfSelection %= Registry.NUM_VF;
}
public function keyUp(evt:KeyboardEvent):void {
}
}
}