xxxxxxxxxx
42
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// PolarToCartesian
// Convert a polar coordinate (r,theta) to cartesian (x,y):
// x = r * cos(theta)
// y = r * sin(theta)
let r;
let theta;
function setup() {
createCanvas(640, 360);
// Initialize all values
r = 0;
theta = 0;
background(51);
}
function draw() {
// Translate the origin point to the center of the screen
translate(width / 2, height / 2);
// Convert polar to cartesian
let x = r * cos(theta);
let y = r * sin(theta);
// Draw the ellipse at the cartesian coordinate
ellipseMode(CENTER);
fill(127);
noStroke();
// stroke(255);
// strokeWeight(2);
//line(0, 0, x, y);
ellipse(x, y, 10, 10);
// Increase the angle over time
r += 0.1;
theta += 0.02;
}