xxxxxxxxxx
44
function setup() {
createCanvas(600, 600);
p0 = createVector(0, height/2)
p1 = createVector(width/2, height)
p2 = createVector(width, height/2)
}
function draw() {
background(0);
stroke(255)
strokeWeight(1)
colorMode(HSB)
// Controlando o anchor point com o mouse
p1.x = mouseX;
p1.y = mouseY;
// Fazer lerp para p0-p1 e p1-p2
noFill()
beginShape();
const delta = 0.05
for(t = 0; t< 1.0001; t+= delta) { // 1.0001 é para evitar erro de arrendondamento do JS e fazer a última linha ligando os últimos dois pA e pB
pAx = lerp (p0.x, p1.x, t);
pAy = lerp (p0.y, p1.y, t);
pBx = lerp (p1.x, p2.x, t);
pBy = lerp (p1.y, p2.y, t);
stroke(t*360, 255, 255)
strokeWeight(1)
line(pAx, pAy, pBx, pBy)
pCx = lerp (pAx, pBx, t)
pCy = lerp (pAy, pBy, t)
// vertex(pCx, pCy);
stroke(255)
strokeWeight(3)
point(pCx, pCy);
}
endShape();
}