-
Notifications
You must be signed in to change notification settings - Fork 0
/
rendering_handling.js
63 lines (50 loc) · 1.97 KB
/
rendering_handling.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
// REQUEST ANIMATION BINDING //
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x ) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|| window[vendors[x]+'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
};
if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}());
// RENDER LOOP //
var render = function(){
ctx.clearRect(0,0,700,500);
for (var i = 0; i < node_grids.length; i++) {
var first_node = node_grids[i][0];
var second_node = node_grids[i][1];
draw_spline( first_node , second_node , ctx);
}
requestAnimationFrame(render);
};
var update_rendering_array = function (connection_array, add_array){
for (var i = 0; i < node_grids.length; i++) {
for (var n = 0; n < 2; n++) {
if(node_grids[i][n].id === connection_array[0].id || node_grids[i][n].id === connection_array[1].id ){
node_grids[i][0].connection = undefined;
node_grids[i][1].connection = undefined;
node_grids.splice(i, 1);
break;
}
}
}
if(add_array){
connection_array[0].connection = connection_array[1];
connection_array[1].connection = connection_array[0];
node_grids.push(connection_array);
}
};