Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mozilla arch JS code
function curveInArchCoords(col, rows, cols) {
const mathX = col / cols * 2 * Math.PI;
const mathY = Math.cos(mathX);
const archY = (1 + mathY) / 2 * rows;
return archY;
}
function setFrame(frame, rows, cols, colOffset) {
for (const i of frame) {
frame[i] = 0;
}
for (let col = 0; col < cols; col++) {
const row = Math.floor(curveInArchCoords(col + colOffset, rows, cols));
const offset = (row * cols + col) * 3;
const red = col / cols * 255;
const green = 0;
const blue = row / rows * 255;
frame[offset] = red;
frame[offset + 1] = green;
frame[offset + 2] = blue;
}
}
export function transform(buffer, rows, cols, frameCount, fps, isFirst) {
const frameSize = 3 * rows * cols;
for (let i = 0; i < frameCount; i++) {
const second = i / fps;
const frame = new Uint8Array(buffer, frameSize * i, frameSize);
setFrame(frame, rows, cols, second * 4);
}
}
export default function () {
return { transform };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.