-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
743210e
commit 185c419
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { Checkboxland } from '../../../src/index.js'; | ||
|
||
const width = 44; | ||
const height = 15; | ||
const dimensions = `${width}x${height}`; | ||
const frames = [] | ||
|
||
let interval = 100; | ||
let cbl; | ||
let timeoutId; | ||
let startTime; | ||
let elapsedTimeSeconds; | ||
|
||
function init(existingCbl) { | ||
cbl = !!existingCbl ? existingCbl : new Checkboxland({ dimensions }); | ||
startTime = performance.now(); | ||
|
||
loop(); | ||
|
||
return cbl; | ||
} | ||
|
||
function simpleWave(x, y, t) { | ||
let frequencyConstant = 0.9; | ||
let scaledTime = t * 3; | ||
|
||
// For reference, see https://www.desmos.com/calculator/bp9t79pfa0 | ||
return y < 5 * Math.sin((x - scaledTime) / frequencyConstant); | ||
} | ||
|
||
function hypotenuseLength(x, y) { | ||
return Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); | ||
} | ||
|
||
function reIndexY(y) { | ||
// transform y to a more traditional scale (puts y=0 in the center | ||
// of the grid with positive values above and negative values below). | ||
return (height - 1 - y) - ((height - 1) / 2) | ||
} | ||
|
||
function reIndexX(x) { | ||
// transform x to a more traditional scale (puts x=0 in the center | ||
// of the grid with positive values right and negative values left). | ||
return (width - x) - (width / 2) | ||
} | ||
|
||
function loop() { | ||
let checkboxState; | ||
let newMatrix = []; | ||
|
||
elapsedTimeSeconds = (performance.now() - startTime) / 1000; | ||
|
||
for (let y = 0; y < height; y++) { | ||
newMatrix[y] = []; | ||
for (let x = 0; x < width; x++) { | ||
let reIndexedY = reIndexY(y); | ||
let reIndexedX = reIndexX(x); | ||
|
||
let radialX = hypotenuseLength(reIndexedX, reIndexedY); | ||
|
||
checkboxState = simpleWave(radialX, 0, elapsedTimeSeconds); | ||
newMatrix[y][x] = checkboxState ? 1 : 0; | ||
} | ||
} | ||
|
||
cbl.setData(newMatrix); | ||
|
||
timeoutId = setTimeout(loop, interval); | ||
} | ||
|
||
function cleanUp() { | ||
clearInterval(timeoutId); | ||
} | ||
|
||
export { | ||
init, | ||
cleanUp, | ||
dimensions, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Ripple</title> | ||
|
||
<link rel="icon" type="image/png" sizes="16x16" href="../../favicon.png"> | ||
|
||
<style> | ||
body { | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="page"> | ||
<div id="checkboxland"></div> | ||
</div> | ||
<script type="module"> | ||
import * as ripple from './demo.js'; | ||
ripple.init(); | ||
</script> | ||
</body> | ||
|
||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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