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 p5;
|
||||||
|
export var p5vector;
|
||||||
export var p5loaded = new Promise(async function(resolve, reject) {
|
export var p5loaded = new Promise(async function(resolve, reject) {
|
||||||
var success = false;
|
var success = false;
|
||||||
try {
|
try {
|
||||||
@ -13,5 +14,6 @@ export var p5loaded = new Promise(async function(resolve, reject) {
|
|||||||
catch {}
|
catch {}
|
||||||
console.log('Used local fallback for p5'); }
|
console.log('Used local fallback for p5'); }
|
||||||
p5 = window.p5;
|
p5 = window.p5;
|
||||||
|
p5vector = window.p5.Vector
|
||||||
delete window.p5;
|
delete window.p5;
|
||||||
if (success) { resolve(); } else { reject(); }});
|
if (success) { resolve(); } else { reject(); }});
|
||||||
|
@ -1,13 +1,25 @@
|
|||||||
# PolyTree, intended to be loaded as a module
|
# 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) ->
|
sketch = (p) ->
|
||||||
|
pos = null
|
||||||
|
vel = null
|
||||||
|
abs = Math.abs # For convenience
|
||||||
|
|
||||||
p.setup = =>
|
p.setup = =>
|
||||||
p.createCanvas window.innerWidth, 575, p.WEBGL
|
p.createCanvas window.innerWidth, 575, p.WEBGL
|
||||||
p.background 224
|
p.background 224
|
||||||
p.ellipse 0, 0, 100, 50
|
p.frameRate 5
|
||||||
p.ellipse p.width/4, -p.height/4, 50, 100
|
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 = () ->
|
show = () ->
|
||||||
P5 = new p5 sketch
|
P5 = new p5 sketch
|
||||||
|
Loading…
Reference in New Issue
Block a user