xxxxxxxxxx
50
let angle = 0;
let outer_radius = 250;
let initial_radius = 5;
function setup() {
createCanvas(1000, 1000);
fill(0);
}
function draw() {
draw_Fermat_spiral();
}
function draw_Fermat_spiral()
{
// Co-ordinates of spiral ball which is determined by the position of cursor
let x_val = cos(angle) * outer_radius + mouseX;
let y_val = sin(angle) * outer_radius + mouseY;
// Drawing the ball
stroke(10);
fill(255,242,229);
ellipse(x_val, y_val, initial_radius, initial_radius);
// Updating parameters required to determine x_val and y_val
angle = angle - 1;;
outer_radius = outer_radius - 0.5;
// As long as the ball co-incides with the cursor, change the background
// if (x_val === mouseX && y_val === mouseY)
// background(255, 0, 0);
// // If the ball goes out of canvas, update angle, x_val and y_val accordingly
// if (x_val < 0 || x_val > width || y_val < 0 || y_val >height)
// {
// angle = 0;
// x_val = mouseX;
// y_val = mouseY;
// }
}