-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
77 lines (57 loc) · 1.69 KB
/
setup.js
File metadata and controls
77 lines (57 loc) · 1.69 KB
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
//I claim no rights to this code, I did not create this code. It was given to me. I have not altered it from its original state.
!function() {
var XscaleFactor =0.9;
var YscaleFactor = 0.8;
/*
* Draw: object to manage window resizing and canvas creation.
* Call Draw.init() to start drawing loop.
*/
window.Draw = {
canvas: document.querySelector( 'canvas' ),
ctx: null,
/*
width: window.innerWidth,
height: window.innerHeight,*/
width: window.innerWidth*XscaleFactor,
height: window.innerHeight*YscaleFactor,
init: function() {
this.ctx = this.canvas.getContext( '2d' )
this.Graph.draw = this.Graph.draw.bind( this.Graph )
Draw.resize()
window.onresize = Draw.resize
window.requestAnimationFrame( this.Graph.draw )
},
resize: function() {
Draw.width = window.innerWidth*XscaleFactor,
Draw.height = window.innerHeight*YscaleFactor
Draw.canvas.setAttribute( 'width', Draw.width )
Draw.canvas.setAttribute( 'height', Draw.height )
},
/*
* Draw.Graph: manage animation / children. Each child
* pushed to the children array should have both a
* render() and a animate() method. Override setup to get
* a per-frame callback.
*/
Graph: {
children: [],
draw: function() {
this.setup()
this.animate()
this.render()
window.requestAnimationFrame( this.draw )
},
setup: function() {},
animate: function() {
for( var i = 0; i < this.children.length; i++ ) {
this.children[ i ].animate()
}
},
render: function() {
for( var i = 0; i < this.children.length; i++ ) {
this.children[ i ].draw()
}
},
}
}
}()