2021-04-18 18:40:29 +00:00
|
|
|
# PolyTree, intended to be loaded as a module
|
|
|
|
|
2021-04-18 20:15:28 +00:00
|
|
|
import {p5, p5loaded, p5vector} from './lib/loadp5.js'
|
2021-04-18 18:40:29 +00:00
|
|
|
|
|
|
|
sketch = (p) ->
|
2021-04-18 20:15:28 +00:00
|
|
|
pos = null
|
|
|
|
vel = null
|
|
|
|
abs = Math.abs # For convenience
|
|
|
|
|
2021-04-18 18:40:29 +00:00
|
|
|
p.setup = =>
|
|
|
|
p.createCanvas window.innerWidth, 575, p.WEBGL
|
|
|
|
p.background 224
|
2021-04-18 20:15:28 +00:00
|
|
|
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
|
2021-04-18 18:40:29 +00:00
|
|
|
|
|
|
|
show = () ->
|
|
|
|
P5 = new p5 sketch
|
|
|
|
|
|
|
|
p5loaded.then show
|