Created
July 19, 2014 16:36
-
-
Save anonymous/0f4c4e8798d0c3d8998a to your computer and use it in GitHub Desktop.
hexagon worms: http://tmblr.co/ZOLwww1LwMB3j
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
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 | (result[i][0]/samplesPerFrame) << 16 | | |
(result[i][1]/samplesPerFrame) << 8 | (result[i][2]/samplesPerFrame); | |
updatePixels(); | |
saveFrame("f###.gif"); | |
if (frameCount==numFrames) | |
exit(); | |
} | |
} | |
////////////////////////////////////////////////////////////////////////////// | |
int samplesPerFrame = 8; | |
int numFrames = 120; | |
float shutterAngle = .6; | |
boolean recording = true; | |
void setup_() { | |
size(500, 500, P2D); | |
smooth(8); | |
stroke(36); | |
noFill(); | |
} | |
float r = 30; | |
int nlines = 5; | |
float ls, le, ll = .4; | |
float x, y; | |
int N = 8; | |
float sc = .72; | |
float rot, qq; | |
void thing(float q) { | |
q = (q+100)%1; | |
strokeWeight(.9); | |
for (int a=0; a<3; a++) { | |
pushMatrix(); | |
rotate(a*TWO_PI/6); | |
for (int i=-5; i<nlines+5; i++) { | |
ls = map(i+3*t, 0, nlines, -r/2, r/2); | |
le = map(i+ll+3*t, 0, nlines, -r/2, r/2); | |
ls = constrain(ls, -r/2, r/2); | |
le = constrain(le, -r/2, r/2); | |
line(-r*.866, ls, -r*.866, le); | |
} | |
popMatrix(); | |
} | |
strokeWeight(2.3); | |
rot = -int(6*q)*TWO_PI/6; | |
qq = (6*q)%1; | |
pushMatrix(); | |
rotate(rot); | |
ls = lerp(-r/2, r/2, qq)*sc; | |
pushMatrix(); | |
rotate(TWO_PI/6); | |
line(-r*.866*sc, ls, -r*.866*sc, r/2*sc); | |
popMatrix(); | |
line(-r*.866*sc,-r/2*sc,-r*.866*sc,r/2*sc); | |
le = lerp(-r/2, r/2, qq)*sc; | |
pushMatrix(); | |
rotate(-TWO_PI/6); | |
line(-r*.866*sc, -r/2*sc, -r*.866*sc, le); | |
popMatrix(); | |
popMatrix(); | |
} | |
void draw_() { | |
background(245); | |
pushMatrix(); | |
translate(width/2, height/2); | |
rotate(TWO_PI/24); | |
scale(-1, 1); | |
for (int i=-N; i<=N; i++) { | |
for (int j=-N; j<=N; j++) { | |
x = i*r*2*.866; | |
if (j%2 != 0) | |
x += r*.866; | |
y = (j+2/3.0)*r*2*.866*.866; | |
pushMatrix(); | |
translate(x, y); | |
thing(t + atan2(x, y)/TWO_PI - 0.002*dist(x, y, 0, 0)); | |
popMatrix(); | |
} | |
} | |
popMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment