30 lines
802 B
CoffeeScript
30 lines
802 B
CoffeeScript
# PolyTree, intended to be loaded as a module
|
|
|
|
import {p5, p5loaded, p5vector} from './lib/loadp5.js'
|
|
import Deque from './deque.js' # Weird to write it this way when
|
|
# it's implemented in deque.coffee, but oh well.
|
|
|
|
sketch = (p) ->
|
|
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 = =>
|
|
current = leaves.removeRight()
|
|
p.point current
|
|
for step in steps
|
|
leaves.insertLeft current.copy().add(step)
|
|
|
|
show = () ->
|
|
P5 = new p5 sketch
|
|
|
|
p5loaded.then show
|