/* This example highlights one of the interesting aspects of Polar coordinates; as theta increases, object moving only along theta will never leave the screen. */ // The radius at which our object will move float r; // basic components of movement float theta; float theta_vel; float theta_accel; void setup() { // setup the environment size(300, 300); colorMode(RGB, 255, 255, 255, 255); background(0); // give all of our basic values a starting value r = 75.0f; theta = 0.0f; theta_vel = 0.0f; theta_accel = 0.00001f; } void draw() { // Again; we'll be generating values that swing between positive // and negative, so we'll reset the center of the screen (0, 0), to // the actual center of the screen. translate(width / 2, height / 2); rectMode(CENTER); // fade out the background fill(0, 1); rect(0, 0, width, height); // calculate our position, cosine is related to the horizontal, sine to the vertical float x = r * cos(theta); float y = r * sin(theta); // draw our circle noStroke(); fill(0, 0, 255); ellipse(x, y, 20, 20); // apply our forces to theta theta_vel += theta_accel; theta += theta_vel; }