-
Notifications
You must be signed in to change notification settings - Fork 16
/
flow-main.js
145 lines (104 loc) · 2.68 KB
/
flow-main.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var canvDiv;
var flow;
var nodes=[];
var curTime=0;
var fps=60;
var sps=120;
//var t0=0;
var dragging=false;
var mouse=[0,0];
var wiring; // wire under consruction: [srcNode,srcPort,wire,pt]
var play=true;
var socket;
var localSocket={};
function init(){
canvDiv=document.getElementById('container');
if (document.io)
socket=io.connect('http://login.sccs.swarthmore.edu:8201');
makeTypes();
//window.setInterval(step,1000/sps);
//t0=Date.now()/1000;
step();
//window.setInterval(draw,1000/fps);
//this is supposed to be better.
(function animloop(){
requestAnimFrame(animloop);
draw();
})();
var tmpScene=localStorage.getItem('tmpScene');
if(tmpScene){
loadScene(JSON.parse(tmpScene));
}
/*
logger=new nodeTypes.Logger({x:500,y:200});
summer=new nodeTypes.Summer({x:200,y:100});
mou=new nodeTypes.Mouse( {x:100,y:180});
tim=new nodeTypes.Time( {x: 50,y:410});
sin1=new nodeTypes.Sine( {x: 50,y:300,i:{freq:.5}});
sin2=new nodeTypes.Sine( {x:200,y:300,i:{freq:4.05}});
dis=new nodeTypes.Scope( {x:500,y:350});
cus=new nodeTypes.Custom({x:200,y:400});
t2=new nodeTypes.X2( {x:350,y:150});
mkWire(sin1,'y',sin2,'amp',100);
mkWire(sin2,'y',dis,'y1',220);
mkWire(summer,'c',t2,'a',0);
mkWire(t2,'b',logger,'msg',100);
mkWire(tim,'t',cus,'a',320);
mkWire(tim,'t',dis,'x',320);
mkWire(cus,'x',dis,'y2',0);
mkWire(cus,'y',dis,'y3',100);
// mkWire(lfo,'y',dis,'y1',220);
*/
makeLibrary();
// canvDiv.onmousedown=function(e){
// console.log(e);
// }
}
var draw=function draw(){
if(play){
//step();
for(var ii in nodes){
nodes[ii].draw();
}
}
}
// main run loop
var step=function step(){
//curTime=Date.now()/1000-t0;
if(play){
curTime+=1/sps;
for(var ii in nodes){
nodes[ii].eval();
}
for(var ii in nodes){
nodes[ii].progress();
}
}
window.setTimeout(step,1000/sps);
}
function unloading(){
localStorage.setItem('tmpScene',JSON.stringify(exportNodes(nodes)));
}
//misc utility funcs
Math.dist=function(x1,y1,x2,y2){
return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
objectSize = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// shim layer with setTimeout fallback
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000 / 60);
};
})();