polytree/polytree.coffee

30 lines
802 B
CoffeeScript
Raw Permalink Normal View History

# PolyTree, intended to be loaded as a module
import {p5, p5loaded, p5vector} from './lib/loadp5.js'
2021-04-19 04:07:31 +00:00
import Deque from './deque.js' # Weird to write it this way when
# it's implemented in deque.coffee, but oh well.
sketch = (p) ->
2021-04-19 04:07:31 +00:00
leaves = new Deque()
leaves.insertRight p.createVector 0
sides = 5
length = 20
steps = (p5vector.fromAngle(i*p.TAU/sides).mult length for i in [0...sides])
p.setup = =>
p.createCanvas window.innerWidth, 575, p.WEBGL
p.background 224
p.frameRate 5
pos = p.createVector p.width, p.height
p.draw = =>
2021-04-19 04:07:31 +00:00
current = leaves.removeRight()
p.point current
for step in steps
leaves.insertLeft current.copy().add(step)
show = () ->
P5 = new p5 sketch
p5loaded.then show