xxxxxxxxxx
94
var int8 = new Int8Array(4);
var int32 = new Int32Array(int8.buffer, 0, 1);
var float32 = new Float32Array(int8.buffer, 0, 1);
function ibf(i) {
// Reinterpret a 32-bit int as a float
// https://github.com/mattdesl/number-util/blob/master/index.js
int32[0] = i;
return float32[0];
}
function randFloat() {
// Generate a random float that spans the complete range of
// legal 32-bit floating point numbers
// https://medium.com/analytics-vidhya/random-floats-in-any-range-9b40d30b637b
// https://gist.github.com/RHavar/a6511dea4d4c41aeb1eb
let o = new Uint32Array(1);
while (true) {
window.crypto.getRandomValues(o);
let r = ibf(o[0]);
if (
r == Number.POSITIVE_INFINITY ||
r == Number.NEGATIVE_INFINITY ||
isNaN(r)
) {
continue;
}
return r;
}
}
function setup() {
createCanvas(400, 400);
frameRate(20);
}
function draw() {
background(255);
stroke(100, 100, 255);
strokeWeight(0.5);
for (let idx = 0; idx < height; idx += 25) {
line(0, idx, width, idx);
}
stroke(255, 100, 100);
line(50, 0, 50, height);
stroke(0, 160);
strokeWeight(4.0);
fill(255, 255, 0, 20);
let r = randFloat();
// Suppress glitching some of the time.
if (noise(frameCount / 10) < 0.5) {
r = 0;
}
beginShape();
for (let idx = 0; idx < 500; ++idx) {
const ang = r * TWO_PI + (TWO_PI * idx) / 500;
vertex(width - 140 + 100 * cos(ang), 160 + 100 * sin(ang));
}
endShape(CLOSE);
r = randFloat();
if (noise(frameCount / 10) < 0.5) {
r = 0;
}
fill(0, 100, 0, 20);
beginShape();
vertex(-5, height - 100);
for (let idx = 0; idx < width; ++idx) {
let aa = r * r * idx;
let bb = r * r * 10;
vertex(
idx,
height / 2 + 50 + 50 * sin(r * TWO_PI + frameCount / 15 + idx / 30)
);
}
vertex(width + 5, height - 100);
vertex(width + 5, height + 5);
vertex(-5, height + 5);
endShape();
}
function keyPressed() {
if (key == "g") {
saveGif("output", 200, { units: "frames", delay: 0 });
}
}