-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsfluid_canvas.html
55 lines (45 loc) · 1.28 KB
/
jsfluid_canvas.html
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
<!DOCTYPE html>
<meta charset="utf-8" />
<canvas id="canvas" width="400" height="300"></canvas>
<script src="http://code.createjs.com/easeljs-0.6.0.min.js"></script>
<script src="jsfluid.js"></script>
<script>
var canvas, stage;
window.onload = init;
function init() {
canvas = document.getElementById("canvas");
stage = new createjs.Stage(canvas);
createjs.Ticker.setFPS(60);
createjs.Ticker.addListener(stage);
createjs.Ticker.addEventListener("tick", tick);
Module.initialize();
}
function draw_circle(x, y, radius) {
var g = new createjs.Graphics();
g.beginFill("#66f"); //"rgba(150,150,255,0.25");
g.drawCircle(0, 0, radius);
var circle = new createjs.Shape(g);
circle.x = x;
circle.y = y;
stage.addChild(circle);
}
function draw() {
var pts = Module.get_points();
var n = Module.ccall('get_num_points', 'number', null, []);
function norm(x,y) {
return {x: (x/60+0.5) * canvas.width,
y: -y*8+canvas.height, //(1-(y/50)) * canvas.height};
};
}
for (var i = 1; i < n; i++) {
var a = norm(pts[i].x, pts[i].z);
draw_circle(a.x, a.y, 4);
}
}
function tick() {
Module.step();
stage.removeAllChildren();
draw();
stage.update();
}
</script>