-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgravitySimulator.coffee
More file actions
55 lines (38 loc) · 1.07 KB
/
gravitySimulator.coffee
File metadata and controls
55 lines (38 loc) · 1.07 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
#@codekit-prepend helperFunctions.coffee
#@codekit-prepend planet.coffee
#@codekit-prepend io.coffee
$ = jQuery
root = exports ? this
#Get the canvas
#---------------
canvas = document.getElementById "myCanvas"
context = canvas.getContext "2d"
gameObjects = []
computeNextTimestep = ->
for gameObject in gameObjects
gameObject.run()
#Tanslate to the center
context.save()
context.translate canvas.width/2, canvas.height/2
#black out the background
context.fillStyle = rgba 0, 0, 0, 0.5
context.fillRect -1000, -1000, 10000, 10000
#Draw the gameobject
for gameObject in gameObjects
gameObject.show()
context.fillStyle = rgb 100, 100, 100
context.beginPath()
context.arc gameObject.loc.x, gameObject.loc.y, gameObject.radius, 0, 2*Math.PI
context.closePath()
context.fill()
context.restore()
console.log root.drag
setTimeout(computeNextTimestep, root.delay)
root.delay = 0
root.drag = 0
root.power = 2
canvas.width = window.innerWidth
canvas.height = window.innerHeight
for i in [0..10]
gameObjects.push new Planet randomVector()
computeNextTimestep()