Skip to content

Instantly share code, notes, and snippets.

Created September 1, 2014 08:47
Show Gist options
  • Save anonymous/4255977085d958c8df71 to your computer and use it in GitHub Desktop.
Save anonymous/4255977085d958c8df71 to your computer and use it in GitHub Desktop.
hexagon wave
// by dave & beesandbombs
int[][] result;
float t;
void setup() {
setup_();
result = new int[width*height][3];
}
void draw() {
if (!recording) {
t = mouseX*1.0/width;
draw_();
} else {
for (int i=0; i<width*height; i++)
for (int a=0; a<3; a++)
result[i][a] = 0;
for (int sa=0; sa<samplesPerFrame; sa++) {
t = map(frameCount-1 + sa*shutterAngle/samplesPerFrame, 0, numFrames, 0, 1);
draw_();
loadPixels();
for (int i=0; i<pixels.length; i++) {
result[i][0] += pixels[i] >> 16 & 0xff;
result[i][1] += pixels[i] >> 8 & 0xff;
result[i][2] += pixels[i] & 0xff;
}
}
loadPixels();
for (int i=0; i<pixels.length; i++)
pixels[i] = 0xff << 24 |
int(result[i][0]*1.0/samplesPerFrame) << 16 |
int(result[i][1]*1.0/samplesPerFrame) << 8 |
int(result[i][2]*1.0/samplesPerFrame);
updatePixels();
saveFrame("g###.gif");
if (frameCount==numFrames)
exit();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 32;
int numFrames = 72;
float shutterAngle = .4;
boolean recording = false;
void setup_() {
size(800, 600, P3D);
smooth(8);
strokeWeight(3);
rectMode(CENTER);
colorMode(HSB,1);
}
float centreX, centreY, centreZ, x, y, z;
int N = 25;
float r;
float l = 25;
float strokeHue, strokeBrightness;
float maxHeight = 250;
float heit(float a, float b) {
r = max(abs(b),abs(.5*b+.5*sqrt(3)*a),abs(.5*b-.5*sqrt(3)*a));
return map(sin(TWO_PI*t - 0.009*r)*exp(-0.0003*pow(r,1.5)), -1, 1, 0, maxHeight);
}
void draw_() {
background(0);
pushMatrix();
translate(width/2, height*3/4,100);
rotateX(1.1);
rotate(TWO_PI*t/6);
for (int i=-N; i<=N; i++) {
for (int j=-N; j<=N; j++) {
centreX = l*i*sqrt(3);
if (j%2 != 0)
centreX += .5*sqrt(3)*l;
centreY = (j-2/3.0)*l*1.5;
centreZ = heit(centreX, centreY);
for (int a=0; a<3; a++) {
x = centreX + l*sin(TWO_PI*a/3);
y = centreY - l*cos(TWO_PI*a/3);
z = heit(x, y);
strokeHue = map(.5*(z+centreZ), 0, maxHeight,.86,.3);
strokeBrightness = exp(-0.000009*r*r);
stroke(strokeHue,1,strokeBrightness);
line(centreX, centreY, centreZ, x, y, z);
}
}
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment