-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.coffee
44 lines (35 loc) · 939 Bytes
/
tag.coffee
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
class Tag
constructor: ->
@display = new Disp 1024, 768
@ctx = this.display.ctx
@agents = []
thisTag = @
for i in [0..500]
agentX = Math.random() * @display.width
agentY = Math.random() * @display.height
agentHeading = Math.random() * 2 * Math.PI
agentSpeed = Math.random() * 5
@agents.push new
Agent agentX, agentY, agentHeading, agentSpeed
window.requestAnimationFrame =
window.requestAnimationFrame or
window.mozRequestAnimationFrame or
window.webkitRequestAnimationFrame or
window.msRequestAnimationFrame
@step = ->
thisTag.draw()
window.requestAnimationFrame thisTag.step
thisTag
anim: ->
@step()
updateAgents: (agents, width, height) ->
for a in @agents
a.update agents, width, height
drawAgents: ->
for a in @agents
a.draw this.ctx
draw: ->
@display.clear()
@updateAgents @agents, @display.width, @display.height
@drawAgents()
@display.draw()