Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// by david whyte >:)
void setup() {
setup_();
result = new int[width*height][3];
result_ = new int[width*height][3];
}
int[][] result, result_;
float time;
void draw_() {
if (aberrationAmount == 0.0) {
draw__();
return;
}
for (int i=0; i<width*height; i++)
for (int a=0; a<3; a++)
result_[i][a] = 0;
for (int a=0; a<3; a++) {
pushMatrix();
translate(width/2, height/2);
scale(1+0.008*a*aberrationAmount);
translate(-width/2, -height/2);
draw__();
popMatrix();
loadPixels();
for (int i=0; i<pixels.length; i++) {
result_[i][a] = pixels[i] >> (8*(2-a)) & 0xff;
}
}
loadPixels();
for (int i=0; i<pixels.length; i++)
pixels[i] = 0xff << 24 | result_[i][0] << 16 |
result_[i][1] << 8 | result_[i][2];
updatePixels();
}
void draw() {
if (shutterAngle == 0.0) {
time = map(frameCount-1, 0, numFrames, 0, 1) % 1;
draw_();
return;
}
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++) {
time = 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();
}
////////////////////////////////////////////////////
float aberrationAmount = 0.0;
int samplesPerFrame = 8;
int numFrames = 96;
float shutterAngle = .67;
void setup_() {
size(500,500);
noStroke();
}
void hexx(){
beginShape();
for(int i=0; i<6; i++)
vertex(r*cos(TWO_PI*i/6),r*sin(TWO_PI*i/6));
endShape(CLOSE);
}
float r = 31, sp = 2*r;
float x, y;
int N = 6;
float tt, th, t;
void draw__() {
t = time;
background(#FAFAFA);
fill(#B10DC9);
pushMatrix();
translate(width/2, height/2);
for(int i=-N; i<=N; i++){
for(int j=-N; j<=N; j++){
x = i*sp;
y = j*.866*sp;
if(j%2 != 0)
x += .5*sp;
tt = t + 10 - 0.0012*dist(x,y,0,0);
tt %= 1;
th = (2*tt)%1;
th = min(1,1.5*th);
th = 3*th*th - 2*th*th*th;
th = 3*th*th - 2*th*th*th;
th = .5*th + 1.5*th*th - th*th*th;
if(tt >= .5)
th += 1;
pushMatrix();
translate(x,y);
rotate(th*TWO_PI/12);
hexx();
popMatrix();
}
}
popMatrix();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment