Create a gist now

Instantly share code, notes, and snippets.

Processing Spirograph
import processing.opengl.*;
float a,b,h,xpos,ypos,oxpos,oypos,t,ot,d,od,s;
void setup()
{
size(500,500);
colorMode(HSB,360);
background(0);
}
void draw()
{
fill(0,10);
noStroke();
rect(0,0,width,height);
a=mouseX;
b=60;
h=mouseY;
s=0;
for(float i=1;i<361;i+=1)
{
t=radians(i);
ot=radians(i-1);
d=(a-b/b)*t;
od=(a-b/b)*ot;
oxpos=(a-b)*cos(ot)+h*cos(od);
oypos=(a-b)*sin(ot)+h*sin(od);
xpos=(a-b)*cos(t)+h*cos(d);
ypos=(a-b)*sin(t)+h*sin(d);
stroke(s,360,360);
line(250+oxpos,250+oypos,250+xpos,250+ypos);
s++;
}
}
void mouseMoved()
{
// s++;
// if(s>360)s=0;
}
void mousePressed()
{
save("spiro_"+a+"_"+b+"_"+h+".tif");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment