Skip to content

Instantly share code, notes, and snippets.

@thomasboyt
Created October 6, 2012 13:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasboyt/3844892 to your computer and use it in GitHub Desktop.
Save thomasboyt/3844892 to your computer and use it in GitHub Desktop.
Harmonograph in Processing
float d[] = new float[4];
float f[] = new float[4];
float p[] = new float[4];
float E = exp(1);
PVector current_pt;
PVector center;
void setup() {
size(400, 400);
background(255);
d[0] = 0.02;
d[1] = 0.0315;
d[2] = 0.02;
d[3] = 0.02;
f[0] = 2;
f[1] = 6;
f[2] = 1.002;
f[3] = 3;
p[0] = PI/16;
p[1] = 3*PI/2;
p[2] = 13*PI/15;
p[3] = PI;
current_pt = new PVector(0,0);
center = new PVector(200, 200);
drawHarmonograph();
}
float partial(int i, float t) {
return 100 * sin(t*f[i] + p[i]) * pow(E, -d[i]*t);
}
void drawHarmonograph() {
stroke(0);
beginShape();
for (float t = 0; t < 100; t += 0.01) {
current_pt.x = partial(0, t) + partial(1, t);
current_pt.y = partial(2, t) + partial(3, t);
vertex(current_pt.x, current_pt.y);
}
translate(200, 200);
rotate(radians(90));
endShape();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment