polytree/polytree.coffee

28 lines
598 B
CoffeeScript

# PolyTree, intended to be loaded as a module
import {p5, p5loaded, p5vector} from './lib/loadp5.js'
sketch = (p) ->
pos = null
vel = null
abs = Math.abs # For convenience
p.setup = =>
p.createCanvas window.innerWidth, 575, p.WEBGL
p.background 224
p.frameRate 5
pos = p.createVector p.width, p.height
p.draw = =>
if abs(pos.x) > p.width/2 or abs(pos.y) > p.height/2
pos = p.createVector 0
vel = p5vector.random2D().mult 32
else
pos.add vel
p.point pos
show = () ->
P5 = new p5 sketch
p5loaded.then show