Forked from anonymous/gist:1917ea23ef5836381dee
Last active
January 25, 2016 19:06
-
-
Save naikrovek/c874c7025752d96d8947 to your computer and use it in GitHub Desktop.
This file contains 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 w | |
int[][] result; | |
float t, c; | |
float ease(float p) { | |
return 3*p*p - 2*p*p*p; | |
} | |
float ease(float p, float g) { | |
if (p < 0.5) | |
return 0.5 * pow(2*p, g); | |
else | |
return 1 - 0.5 * pow(2*(1 - p), g); | |
} | |
float mn = .5*sqrt(3); | |
void setup() { | |
setup_(); | |
result = new int[width*height][3]; | |
} | |
void draw() { | |
if (!recording) { | |
t = mouseX*1.0/width; | |
c = mouseY*1.0/height; | |
if (mousePressed) | |
println(c); | |
draw_(); | |
} else { | |
for (int i=0; i<width*height; i++) | |
for (int a=0; a<3; a++) | |
result[i][a] = 0; | |
c = 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("f###.gif"); | |
if (frameCount==numFrames) | |
exit(); | |
} | |
} | |
////////////////////////////////////////////////////////////////////////////// | |
int samplesPerFrame = 16; | |
int numFrames = 72; | |
float shutterAngle = .65; | |
boolean recording = false; | |
void setup_() { | |
size(540, 500,P2D); | |
smooth(8); | |
rectMode(CENTER); | |
fill(32); | |
noStroke(); | |
} | |
float xx(int i, int j) { | |
x = i*sp; | |
y = (j+1/3.0)*mn*sp; | |
if (j%2 == 0) | |
x += .5*sp; | |
r = dist(x, y, 0, 0); | |
th = atan2(y, x); | |
r *= pow(1.33, sin(TWO_PI*t-.000035*r*r)*exp(-.00001*r*r)); | |
return r*cos(th); | |
} | |
float yy(int i, int j) { | |
x = i*sp; | |
y = (j+1/3.0)*mn*sp; | |
if (j%2 == 0) | |
x += .5*sp; | |
r = dist(x, y, 0, 0); | |
th = atan2(y, x); | |
r *= pow(1.4, sin(TWO_PI*t-.000035*r*r)*exp(-.00001*r*r)); | |
return r*sin(th); | |
} | |
float ans; | |
float x, y, tt; | |
float sp = 44; | |
int N = 8; | |
float r, th; | |
float x1, x2, y1, y2; | |
float ll = .25; | |
void lin(float x1, float y1, float x2, float y2){ | |
line(lerp(x1,x2,ll), lerp(y1,y2,ll), lerp(x2,x1,ll), lerp(y2,y1,ll)); | |
} | |
void draw_() { | |
background(28,25,24); | |
pushMatrix(); | |
translate(width/2, height/2); | |
for (int i=-N; i<=N; i++) { | |
for (int j=-N; j<=N; j++) { | |
fill(255); | |
noStroke(); | |
ellipse(xx(i, j), yy(i, j), 6, 6); | |
stroke(255); | |
strokeWeight(1.25); | |
noFill(); | |
x1 = xx(i,j); y1 = yy(i,j); | |
x2 = xx(i+1,j); y2 = yy(i+1,j); | |
lin(x1, y1, x2, y2); | |
x2 = xx(i,j+1); y2 = yy(i,j+1); | |
lin(x1, y1, x2, y2); | |
if (j%2 != 0){ | |
x2 = xx(i-1, j+1); y2 = yy(i-1, j+1); } | |
else{ | |
x2 = xx(i+1, j+1); y2 = yy(i+1, j+1); } | |
lin(x1, y1, x2, y2); | |
} | |
} | |
popMatrix(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment