Skip to content

Instantly share code, notes, and snippets.

@bernhardfritz
Last active January 14, 2024 21:57
Show Gist options
  • Select an option

  • Save bernhardfritz/b92293cf8fbbbca032e0e20ce89b8377 to your computer and use it in GitHub Desktop.

Select an option

Save bernhardfritz/b92293cf8fbbbca032e0e20ce89b8377 to your computer and use it in GitHub Desktop.
import p8g, {
background,
createCanvas,
line,
} from 'https://unpkg.com/p8g.js';
const p0 = [50, 50];
const p1 = [300, 100];
const p2 = [200, 300];
p8g.draw = () => {
background(220);
let bn_prev;
for (let t = 0; t <= 1; t += 0.01) {
const bn_x = (1 - t) * [(1 - t) * p0[0] + t * p1[0]] + t * [(1 - t) * p1[0] + t * p2[0]];
const bn_y = (1 - t) * [(1 - t) * p0[1] + t * p1[1]] + t * [(1 - t) * p1[1] + t * p2[1]];
const bn = [bn_x, bn_y];
if (bn_prev) {
line(bn_prev[0], bn_prev[1], bn[0], bn[1]);
}
bn_prev = bn;
}
};
createCanvas(320, 320);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment