Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Created April 14, 2014 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkwok91/ed9552012130d70fa9f1 to your computer and use it in GitHub Desktop.
Save jkwok91/ed9552012130d70fa9f1 to your computer and use it in GitHub Desktop.
super quick super easy envelope
/*
gotta implement this
http://mathgifs.blogspot.com/2013/12/mathematical-envelopes.html
doin' it for the pretty picturez!
(and the math. yeah. the math.)
*/
float theta;
PVector p0, p1;
float multiplicity;
int r = 100;
void setup() {
size(300, 300, P2D);
frameRate(30);
background(0);
p0 = new PVector(0,0);
p1 = new PVector(0,0);
theta = 0.1;
setMult();
shift();
}
void draw() {
if (p0.x != p1.x && p0.y != p1.y) {
stroke(255,100);
translate(width/2, height/2);
line(p0.x, p0.y, p1.x, p1.y);
shift();
theta += 0.1;
}
}
void setPt(PVector p, float increment) {
float inc = increment%TWO_PI;
p.x = r*cos(inc);
p.y = r*sin(inc);
}
void shift() {
setPt(p0, theta);
setPt(p1, theta*multiplicity);
}
void setMult() {
multiplicity = random(1, 4);
text("one endpoint is moving "+multiplicity+" times \nas fast as the other",0,20);
text("click to change ratio",0,height-20);
}
void mousePressed() {
background(0);
setMult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment