xxxxxxxxxx
41
let s;
function setup() {
createCanvas(500, 400);
s = createSlider(-PI * 2, PI * 2, 1, 0.01);
}
function x(t) {
return 0.25 * t * t * t * t - 200;
}
function xprime(t) {
return Math.pow(t, 3);
}
function y(t) {
return 50 * sin(t);
}
function yprime(t) {
return 50 * cos(t);
}
function draw() {
{
push();
translate(width / 2, height / 2);
scale(1, -1);
background(10);
noStroke();
colorMode(HSB);
for (let t = -2 * PI; t < s.value(); t += 0.1) {
const slope = sqrt(Math.pow(yprime(t), 2) + Math.pow(xprime(t), 2));
fill(slope, 255, 255);
circle(x(t), y(t), 5);
}
pop();
}
fill(255);
textSize(20);
text("t = [-2π ," + round(s.value() / PI, 2) + "π]", 10, height - 20);
text("x(t) = .25t⁴ - 200", 10, 20);
text("y(t) = 50sin(t)", 10, 50);
text("Δt = .1", 10, height - 40);
}