-
-
Save slimlime/22b8e6b83538535287183b8b2c6cfb49 to your computer and use it in GitHub Desktop.
Mozilla arch JS code
This file contains hidden or 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
| 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