Skip to content

Instantly share code, notes, and snippets.

@sidgabriel
Created February 5, 2012 11:54
Show Gist options
  • Save sidgabriel/1744978 to your computer and use it in GitHub Desktop.
Save sidgabriel/1744978 to your computer and use it in GitHub Desktop.
Generative Art From The Math of The Rodin Vortex, The Fibonacci Spiral, and The Gielis Superformula
// open code by Sid Gabriel Hubbard, no lic information provided.
// heavily mutated and expanded from Aris Bezas intro to superformula
// http://www.openprocessing.org/portal/?userID=7600
int num = 333;
int colorL=220, k = 0, j=100, i=200;
float x, y, z;
float lmx,mx,xofset;
float lmy,my,yofset;
float r, th=0, step,lstep=.1, epi,lepi=400;
float m,tm,lm = 1, n1,ln1=1, n2,ln2=0, n3,ln3=0;
float b=1, a=1;
int counter1=0, counter2=0;
int counter1end = 180;
int counter2end = 360;
boolean staticLoc = true;
boolean undernum =false;
boolean mover =false;
boolean sect = false;
PImage gridness;
float gm = 1.6180339887498948482;
float gr = 1/gm;
boolean unitus=true;
float tn1=random(1.7);
float tn2=random(2.9);
float tn3=random(3.7);
float tepi=random(217, 371);
float tstep=random(1.47, 2.17);
float tmx,tmy;
void setup()
{
gridness = loadImage("http://theoneone.com/sourcerequires/overunitus.png");
size(848,480,OPENGL);
tmx=width*.39;
tmy=height*.19;
mx=width*.36;
lmx=width*.36;
xofset=width*.37;
yofset=height*.18;
my=height*.17;
lmy=height*.17;
frameRate(96);
smooth();
loadPixels();
}
void draw()
{
noCursor();
fill(0,0,0,pow(n1,n2+n3));
tint(epi*n3, epi*n2,epi*n1,(n1+n2+n3)/3*gr);
counter1++;
if (counter1 == counter1end) {
lm=tm;
ln1=tn1;
ln2=tn2;
ln3=tn3;
lepi=tepi;
lstep=tstep;
lmx=mx;
lmy=my;
mx=tmx;
my=tmy;
m=tm;
n1=tn1;
n2=tn2;
n3=tn3;
epi=tepi;
step=tstep;
if(mover){tmx=random(width/10,width);
tmy=random(gm,height*gr);}else{tmx=lmx;tmy=lmy;}
tm=9;
tn1=random(width*.002)*gm;
// println(tn1);
tn2=random(width*.003)*gm;
// println(tn2);
tn3=random(width*.004)*gr;
// println(tn3);
tepi=random(width/gm, width*gm);
tstep=random(1.47, 3.17);
if(tn2>tn3){
pictrans();
}
if(tn1>tn2){
unitus=!unitus;
}
if(tn1>tn3){
undernum=!undernum;
}
counter1 = 0;
}
counter2++;
if (counter2 == counter2end) {
mover=!mover;
counter2 = 0;
}
m=map(counter1, 1,counter1end,lm,tm);
mx=map(counter1, 1,counter1end,lmx,tmx);
my=map(counter1, 1,counter1end,int(lmy),int(tmy));
xofset=mx;//println(mx);
yofset=my;//println(my);
if(undernum){
n1=map(counter1, counter1,counter1end,n1,tn1);
n2=map(counter1, counter1,counter1end,ln2,tn2);
n3=map(counter1, counter1,counter1end,ln3,tn3);
epi=map(counter1, counter1,counter1end,lepi,tepi);
step=map(counter1, counter1,counter1end,lstep,tstep);
}else{
n1=map(counter1, 1,counter1end,ln1,tn1);
n2=map(counter1, 1,counter1end,ln2,tn2);
n3=map(counter1, 1,counter1end,ln3,tn3);
epi=map(counter1, 1,counter1end,lepi,tepi);
step=map(counter1, 1,counter1end,lstep,tstep);
}
if(staticLoc){translate(xofset,yofset);}else{translate(mouseX, mouseY);println(width+":w m:"+mouseX);}//width/2,height/4)
//box(50);
noFill();
beginShape();
for (int i=1; i < num; i++) {
r = (epi*n1)*pow(((pow(abs(cos(m*th/4)/a), n2))+(pow(abs(sin(m*th/4)/b), n3))), (-1/n1));
th = th + step;
x = r*cos(th);
y = r*sin(th);
stroke(abs(epi+r)*gr,abs(epi+r)*gr,abs(epi+r)*gr, abs(n1));
strokeWeight(n1);//n2);
curveVertex(x, y);
curveVertex(radians(x), radians(y));
}
if(unitus){endShape(CLOSE); beginShape();}
for (int i=1; i < num; i++) {
r = (epi*n2)*pow(((pow(abs(cos(m*th/4)/a), n2))+(pow(abs(sin(m*th/4)/b), n3))), (-1/n1));
th = th + step;
x = r*cos(th);
y = r*sin(th);
stroke(abs(epi)*r,abs(epi)*r,abs(epi)*r, abs(n2));
strokeWeight(n2);
curveVertex(x, y);
curveVertex(radians(x), radians(y));
}
if(unitus){endShape(CLOSE); beginShape();}
for (int i=1; i < num; i++) {
r = (epi*n3)*pow(((pow(abs(cos(m*th/4)/a), n2))+(pow(abs(sin(m*th/4)/b), n3))), (-1/n1));
th = th + step;
x = r*cos(th);
y = r*sin(th);
stroke(abs(epi)*(r*gr),abs(epi)*(r*gr),abs(epi)*(r*gr), abs(n3));
strokeWeight(abs(n3));//n2);
curveVertex(x, y);
curveVertex(radians(x), radians(y));
}
endShape(CLOSE);
beginShape();
for (int i=1; i < num; i++) {
r = (epi)*pow(((pow(abs(cos(m*th/4)/a), n2))+(pow(abs(sin(m*th/4)/b), n3))), (-1/n1));
th = th + step;
x = r*cos(th);
y = r*sin(th);
stroke(abs(epi)*(r*gr),abs(epi)*(r*gr),abs(epi)*(r*gr), abs(n3));
strokeWeight(abs(n3));//n2);
if(sect){vertex(x,y);
vertex(radians(x),radians(y));}else{
curveVertex(x, y);
curveVertex(radians(x), radians(y));
}
}
endShape(CLOSE);
if(staticLoc){
translate(0-xofset,0-yofset);//width*2-mouseX,height*4-mouseY);
}else{
translate(width-mouseX,height-mouseY);println(width+":w m:"+mouseX);//////println(" "+mouseX+"w h"+mouseY+" ");
}
tint(epi*n1,epi*n2,epi*n3,sq(n1+n2+n3)*gr);//sq(n3*gm));
image(gridness,0,0,width,height);
}
void mousePressed() {
if(mouseButton == RIGHT){
staticLoc=!staticLoc;
counter1=0;
}else{
if (counter1end < counter1) {
counter1 = counter1end-10;
}
else {
counter1 = counter1end+1;
}
}
}
void keyPressed() {
if (key == 'O'){
gridness = loadImage("http://theoneone.com/sourcerequires/overunitus.png");
}
if (key == 'M'){
mover=!mover;
}
if (key == 'U'){
undernum=!undernum;
}
if (key == 'S'){
unitus=!unitus;
}
if (key == 'T'){
sect=!sect;
}
if (key == 'B'){
gridness = loadImage("http://theoneone.com/sourcerequires/open.png");
}
if (key == 'P'){
gridness = loadImage("http://theoneone.com/sourcerequires/prophecy.png");
}
if (key == 'A'){
gridness = loadImage("http://theoneone.com/sourcerequires/outside.png");
}
if (key == 'C'){
save("prophecy.png");
gridness = loadImage("http://theoneone.com/sourcerequires/prophecy.png");
}
if (key == TAB){
save("generated"+"_"+month()+"_"+day()+"_"+m+n1+n2+n3+epi+step+"_"+millis()+second()+".png");
}
if (key == ' ') {
if (counter1end < counter1) {
counter1 = counter1end-1;
}
else {
counter1 = counter1end+1;
}
}
}
void pictrans(){
int caseint = int(random(3,6));
switch(caseint) {
case 0:
break;
case 3:
gridness = loadImage("http://theoneone.com/sourcerequires/prophecy.png");
//undernum=true;
break;
case 4:
gridness = loadImage("http://theoneone.com/sourcerequires/open.png");
break;
case 5:
gridness = loadImage("http://theoneone.com/sourcerequires/outside.png");
break;
case 6:
gridness = loadImage("http://theoneone.com/sourcerequires/overunitus.png");
break;
}
}
@sidgabriel
Copy link
Author

This was written in the Processing 2.0a4 Preview Release. Get it at http://processing.org/download/ paste this code into a new window and hit play. Make sure you are in Standard mode and not Android or JS. It will run but may not display correctly with Processing 1.xx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment