Created
June 4, 2019 12:13
-
-
Save SpaceK33z/7fe3e0f9949a6889b9f2b6e3a3b6d162 to your computer and use it in GitHub Desktop.
Modulaser out of bounds 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
export function streamFrame(_points: Point[]) { | |
// TODO: dunno how expensive this function call is but it could be done less | |
const applyPerspective = dacConfig.projectionMap | |
? projectionMap(dacConfig.projectionMap) | |
: DEFAULT_PROJECTION_MAP; | |
let blankedPrevious = false; | |
scene.points = _points.reduce((acc: Point[], p: Point) => { | |
let { x, y } = p; | |
const { r, g, b } = p; | |
const outOfBounds = | |
dacConfig.blankOutOfBounds && (x < 0 || x > 1 || y < 0 || y > 1); | |
if (outOfBounds && blankedPrevious) { | |
// Skip if already blanked previous and still out of bounds. | |
return acc; | |
} | |
if (dacConfig.blankOutOfBounds) { | |
x = Math.max(Math.min(x, 1), 0); | |
y = Math.max(Math.min(y, 1), 0); | |
} | |
const coordinates = applyPerspective(x, y); | |
x = Math.max(Math.min(coordinates[0], 1), 0); | |
y = Math.max(Math.min(coordinates[1], 1), 0); | |
if (outOfBounds) { | |
// Add wait before laser goes off. | |
for (let index = 0; index < 8; index++) { | |
acc.push({ x, y, r, g, b }); | |
} | |
blankedPrevious = true; | |
return acc; | |
} | |
if (blankedPrevious) { | |
// Add blanking points on new coordinates. | |
for (let index = 0; index < 20; index++) { | |
acc.push({ x, y, r: 0, g: 0, b: 0 }); | |
} | |
} | |
acc.push({ x, y, r, g, b }); | |
blankedPrevious = false; | |
return acc; | |
}, []); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment