Skip to content

Instantly share code, notes, and snippets.

@beesandbombs
Created October 3, 2020 17:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beesandbombs/35f2870847ea1b9864e5bf6cc2043744 to your computer and use it in GitHub Desktop.
Save beesandbombs/35f2870847ea1b9864e5bf6cc2043744 to your computer and use it in GitHub Desktop.
wheels
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), ia = atan(sqrt(.5));
float c01(float g) {
return constrain(g, 0, 1);
}
void draw() {
if (recording) {
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###.png");
if (frameCount==numFrames)
exit();
} else if (preview) {
c = mouseY*1.0/height;
if (mousePressed)
println(c);
t = (millis()/(20.0*numFrames))%1;
draw_();
} else {
t = mouseX*1.0/width;
c = mouseY*1.0/height;
if (mousePressed)
println(c);
draw_();
}
}
//////////////////////////////////////////////////////////////////////////////
int samplesPerFrame = 8;
int numFrames = 420;
float shutterAngle = 1;
boolean recording = false,
preview = true;
void setup() {
size(750, 750, P3D);
smooth(8);
rectMode(CENTER);
result = new int[width*height][3];
noFill();
strokeWeight(5);
}
float x, y, z, tt;
int N = 6;
float r = 180;
color c1, c2;
float sc;
PImage fr;
void draw_() {
sc = map(cos(TWO_PI*2*t),1,-1,0.001,1.5);
strokeWeight(8/pow(sc, 1/3.0));
background(14,12,10);
push();
translate(width/2, height/2);
scale(-1,1,1);
if (t<=.5) {
c1 = #15729d;
c2 = #c53133;
t = 2*t;
scale(1,1,-1);
} else {
c2 = #15729d;
c1 = #c53133;
t = 2*t - 1;
}
scale(1, 1, sc);
rotateY(HALF_PI*t);
stroke(c2);
circle(0, 0, 2*r);
for (int i=0; i<N; i++) {
push();
rotate(PI*i/N*ease(1-t, 2) - HALF_PI);
rotateX(HALF_PI);
stroke(c1);
circle(0, 0, 2*r);
stroke(c2);
if (i==N/2) {
for (int j=0; j<N; j++) {
push();
rotate(PI*j/N);
line(-r, 0, r, 0);
pop();
}
}
pop();
}
pop();
fr = get();
fr.loadPixels();
loadPixels();
for(int i=0; i<pixels.length; i++){
pixels[i] = color(
red(fr.pixels[constrain(i-3,0,pixels.length-1)]),
green(fr.pixels[constrain(i,0,pixels.length-1)]),
blue(fr.pixels[constrain(i+3,0,pixels.length-1)]));
}
updatePixels();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment