Skip to content

Instantly share code, notes, and snippets.

@echophon
Created September 4, 2014 01:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save echophon/b2831c8f241ea77a09d9 to your computer and use it in GitHub Desktop.
Save echophon/b2831c8f241ea77a09d9 to your computer and use it in GitHub Desktop.
/*
Op Stack - Yancy Way 2014
Requires HYPE.pde
*/
float a, b, m, n1, n2, n3, radius;
float theta;
float r1, r2, r3, r4, r5, r6;
HOscillator o1, o2, o3, o4;
void setup() {
size(500,500);
//HYPE section
//this could be replaced by some other sine function
//generates smooth sine waves to oscillate the SuperShape
H.init(this).background(H.CLEAR).autoClear(true);
o1 = new HOscillator().speed(0.25).freq(16);
o2 = new HOscillator().speed(2).freq(2);
o3 = new HOscillator().speed(0.5).freq(8);
o4 = new HOscillator().speed(0.125).freq(8);
//end HYPE section
a = 2; //scale x
b = 2; //scale y
m = 12; // # of sides for our shape
n1 = 2;
n2 = 2;
n3 = 4;
radius = 200; //overall scale
// create some random values to oscillate between and feed to sshape
r1 = random(0,4);
r2 = random(0,4);
r3 = random(0,4);
r4 = random(0,4);
r5 = random(0,4);
r6 = random(0,4);
println("r1= "+ r1);
println("r2= "+ r2);
println("r3= "+ r3);
println("r4= "+ r4);
println("r5= "+ r5);
println("r6= "+ r6);
}
// SuperFormula see http://en.wikipedia.org/wiki/Superformula
// the values are for this are oscillated in draw() creating a morphing shape
void sshape(float a, float b, float m, float n1, float n2, float n3, float radius){
beginShape();
for(theta = 0; theta <TWO_PI+0.001; theta+=0.001)
{
float raux = pow(abs(1.0/a)*abs(cos((m*theta/4.0))),n2) + pow(abs(1.0/b)*abs(sin(m*theta/4.0)),n3);
float r = radius*pow(abs(raux),(-1.0/n1));
float x=r*cos(theta);
float y=r*sin(theta);
vertex(x,y);
}
endShape();
}
void draw() {
background(#111111, 10);
// nextRaw returns -1,1
// m = map(o1.nextRaw(), -1, 1, 24, 6);
n1 = map(o2.nextRaw(), -1, 1, r1, r2 );
// n2 = map(o3.nextRaw(), -1, 1, r3, r4 );
n3 = map(o4.nextRaw(), -1, 1, r5, r6 );
pushMatrix();
translate(width/2,height/2);
rotate(HALF_PI);
for (int i = 0; i < 20; i++ ){
rotate(PI/20);
if (i%2 == 0){
fill(#C0FEA1);
}
else{
fill(#111111);
}
noStroke();
// layer the shapes in an alternating order, decreasing the radius each time
sshape(a, b, m, n1, n2, n3, radius-(i*10) );
}
popMatrix();
frame.setTitle(int(frameRate) + " fps");
if (frameCount%2==0 && frameCount >=0 && frameCount<361){
saveFrame("image-####.gif");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment