Created
February 14, 2024 13:26
-
-
Save beesandbombs/6be885fa098e75634c86b40436f4050a to your computer and use it in GitHub Desktop.
lights
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
float[][] result; | |
float t, c; | |
float ease(float p) { | |
p = c01(p); | |
return 3*p*p - 2*p*p*p; | |
} | |
float ease(float p, float g) { | |
p = c01(p); | |
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); | |
} | |
float millisFrame1; | |
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); | |
t %= 1; | |
draw_(); | |
loadPixels(); | |
for (int i=0; i<pixels.length; i++) { | |
result[i][0] += sq(red(pixels[i])/255.0); | |
result[i][1] += sq(green(pixels[i])/255.0); | |
result[i][2] += sq(blue(pixels[i])/255.0); | |
} | |
} | |
loadPixels(); | |
for (int i=0; i<pixels.length; i++) | |
pixels[i] = color(255*sqrt(result[i][0]/samplesPerFrame), | |
255*sqrt(result[i][1]/samplesPerFrame), | |
255*sqrt(result[i][2]/samplesPerFrame)); | |
updatePixels(); | |
saveFrame("f###.png"); | |
if (frameCount==numFrames) | |
exit(); | |
} else if (preview) { | |
if (frameCount==1) | |
millisFrame1 = millis(); | |
c = mouseY*1.0/height; | |
if (mousePressed) | |
println(c); | |
t = ((millis()-millisFrame1)/(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 = 450; | |
float shutterAngle = .6; | |
boolean recording = false, | |
preview = true; | |
void setup() { | |
size(750, 750, P3D); | |
smooth(8); | |
rectMode(CENTER); | |
pixelDensity(recording ? 1 : 2); | |
result = new float[width*height][3]; | |
noStroke(); | |
blendMode(ADD); | |
} | |
color[] cs = { #df0000, #00df00, #0000df}; | |
float x, y, z, tt; | |
int N = 12; | |
float l = 18, sp = 20; | |
float ph; | |
int in1, in2, in; | |
void draw_() { | |
background(10); | |
push(); | |
translate(width/2, height/2); | |
for (int a=0; a<3; a++) { | |
fill(cs[a]); | |
for (int i=-12; i<12; i++) { | |
for (int j=-12; j<12; j++) { | |
x = (i+.5)*sp; | |
y = (j+.5)*sp; | |
in1 = i; | |
if (i<0) | |
in1 = -i-1; | |
in2 = j; | |
if (j<0) | |
in2 = -j-1; | |
in = 12-max(in1, in2); | |
tt = (t*in+120+atan2(x, y)/TAU-.03*a)%1; | |
l = (sp*.95)*ease(25*tt)*c01(sq(1-1.25*tt)); | |
rect(x, y, l, l, 3); | |
} | |
} | |
} | |
pop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment