#canvas {
height: 400px;
}
View Compiled
Pts.quickStart('#canvas', '#fafafa');
let de = new Delaunay();
let triangles = [];
let cells = [];
let lastPt = new Pt();
space.add({
start: (bound) => {
de = Create.delaunay( Create.distributeRandom( space.innerBound, 20 ) );
triangles = de.delaunay();
cells= de.voronoi();
},
animate: (time, ftime) => {
form.fill("#0c9").points( de, 2, "circle" );
form.strokeOnly("#0fc").polygons( cells );
},
action: (type, x, y) => {
console.log(de.length);
if (type == "move" && de.length < 100) {
let p = new Pt(x,y);
if (lastPt.$subtract(p).magnitudeSq() > 400) {
lastPt = p;
de.push( p );
triangles = de.delaunay();
cells= de.voronoi();
}
}
if (de.length === 100) {
de.shift();
}
},
});
space.bindMouse().bindTouch().play();
View Compiled
This Pen doesn't use any external CSS resources.