xxxxxxxxxx
83
/*
This script can render avi's and gifs. Setup recording in setup().
Press enter to start and stop recording.
Will also stop recording after recording 'FRAMES' frames. Use this for perfect loops :)
libraries used:
Video Builder: https://github.com/theshock/VideoBuilder
gif.js: https://github.com/jnordberg/gif.js
download: https://github.com/rndme/download
*/
const FRAMES = 3000;
const FPS = 60;
let rec;
let s;
function setup() {
// s = min(windowWidth, windowHeight); // fill window
// s = 1080; // avi recording
s = 720; // gif recording
const canvas = createCanvas(s, s);
frameRate(FPS);
rec = setupRecording("Tiny Flock", canvas, FRAMES, {
// comment out this avi object if you don't want to record avi
avi: {
fps: 60,
quality: 0.92
},
// comment out this gif object if you don't want to record avi
// gif: {
// fps: 30, // 50 is max (set FPS to 50 to see what this recording would look like)
// quality: 1, // lower is better (1 = best). Works to reduce filesize but fucks with colour, would recommend lowering fps instead ✌️
// workers: 1, // multithreaded workers
// }
});
}
function keyPressed(evt) {
if (evt.key == "Enter") {
if (!rec.recording) {
rec.start();
frameCount = 0; // reset time
} else
rec.stop();
}
}
let t;
function draw() {
t = fract(frameCount / FRAMES);
drawScene();
if (rec.recording)
rec.recordFrame();
}
f=Array(99).fill().map((v, i) => [0,0,i])
drawScene=_=> {
createCanvas(s=720, s);
f=f.map(([x,y,a]) => (
fill(a*99,0,255),
rect(x,y,a*9),
[
(x + cos(a)*8)%720,
(y + sin(a)*8)%720,
(a + f.reduce((m,[u,v,w]) => (
d = dist(x,y,u,v) * 0.000001,
m
- w * d
+ (atan2(y-v,x-u) + PI) * d
),0))*0.9
]
));
}