Created
August 21, 2014 20:38
-
-
Save anonymous/dbdc5985f5977101b82b to your computer and use it in GitHub Desktop.
hexagon wave — http://tmblr.co/ZOLwww1Oq4eCA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(500, 500, P3D); | |
smooth(8); | |
strokeWeight(2.7); | |
rectMode(CENTER); | |
colorMode(HSB,1); | |
} | |
float centreX, centreY, centreZ, x, y, z; | |
int N = 20; | |
float r; | |
float l = 18; | |
float strokeHue, strokeBrightness; | |
float maxHeight = 200; | |
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.00002*r*r), -1, 1, 0, maxHeight); | |
} | |
void draw_() { | |
background(0); | |
pushMatrix(); | |
translate(width/2, height*3/4,100); | |
rotateX(1.05); | |
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(z, 0, maxHeight,.8,.5); | |
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