Last active
October 7, 2019 15:26
-
-
Save racecraftr/f4ade19b08608624831bd44d1556a22c to your computer and use it in GitHub Desktop.
makes a colorful cardioid!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// declares the universal variables: r (radius) and theta (the angle) | |
float r; | |
float theta; | |
//sets up the program. | |
void setup(){ | |
size(600, 600);//* | |
r = height * .25;// radius is 1/4 of the height. (this doesn't matter later) | |
theta = 0;//* | |
background(0);//* | |
frameRate(1000);//* | |
} | |
void draw() { | |
stroke(random(255), random(255), 255);// makes a random color (always has blue in it).* | |
strokeWeight(random(5));// makes a random stroke thickness.* | |
translate(width/2, height/2);// moves the top left of the grid to the center of the canvas.* | |
// this translates cartesian coordinates into polar coordinates. | |
float x = r*sin(theta) ; | |
float y = r*cos(theta) ; | |
point(x, y);// makes a point at the specified x and y. | |
theta+=1; // increases theta by 1. | |
// this is the equation for a cardioid: r = x + x(sin(theta)). | |
// we have renamed "x" as "xc" because x has already been used for the coordinates. | |
// feel free to change "xc"! | |
float xc = 100; | |
r = xc+xc* sin(theta); | |
// clears the canvas and starts over the process. | |
if (theta == 360){//* | |
background(0);//* | |
theta = 0;//* | |
} | |
} | |
// *feel free to play around with the variables in these lines. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment