Skip to content

Instantly share code, notes, and snippets.

@Enkerli
Created November 4, 2016 06:06
Show Gist options
  • Select an option

  • Save Enkerli/3f3b4bf5134e3d1cfed5c0258dcea94c to your computer and use it in GitHub Desktop.

Select an option

Save Enkerli/3f3b4bf5134e3d1cfed5c0258dcea94c to your computer and use it in GitHub Desktop.
Colour version of exercise 13-5 in Daniel Shiffman’s Learning Processing book (2015: 249). Enjoying the effect: https://www.dropbox.com/s/k3n7y6m85y49rn7/cartesian-spiral.png?dl=0
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Exercise 13-5: Using Example 13-5, draw a spiral path. Start in the center and move
// outward. Note that this can be done by changing only one line of code and adding one line
// of code!
// A Polar coordinate, radius now starts at 0 to spiral outwards
float r = 1;
float theta = 0;
int c=1;
void setup() {
fullScreen();
// size(640, 360);
background(255);
}
void draw() {
// Polar to Cartesian conversion
float x = 2*r * cos(theta);
float y = 2*r * sin(theta);
// Draw an ellipse at x,y
noStroke();
fill(c*255);
ellipse(x + width/2, y + height/2, 16, 16); // Adjust for center of window
// Increment the angle
theta -= 0.01;
r -=0.02;
c--;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment