feat: incrementally add elements to sketch in draw
This commit is contained in:
parent
63dfa62ffd
commit
de5d35a03f
@ -1,4 +1,5 @@
|
||||
export var p5;
|
||||
export var p5vector;
|
||||
export var p5loaded = new Promise(async function(resolve, reject) {
|
||||
var success = false;
|
||||
try {
|
||||
@ -13,5 +14,6 @@ export var p5loaded = new Promise(async function(resolve, reject) {
|
||||
catch {}
|
||||
console.log('Used local fallback for p5'); }
|
||||
p5 = window.p5;
|
||||
p5vector = window.p5.Vector
|
||||
delete window.p5;
|
||||
if (success) { resolve(); } else { reject(); }});
|
||||
|
@ -1,13 +1,25 @@
|
||||
# PolyTree, intended to be loaded as a module
|
||||
|
||||
import {p5, p5loaded} from './lib/loadp5.js'
|
||||
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.ellipse 0, 0, 100, 50
|
||||
p.ellipse p.width/4, -p.height/4, 50, 100
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user