-
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
2029351
commit 35edb54
Showing
5 changed files
with
95 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,59 @@ | ||
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 getCirclesCheckbox(x, y, t) { | ||
let xOffset = 2*t; | ||
let yOffset = -1.6*t; | ||
let sizeValue = 1; | ||
|
||
// For reference, see https://www.desmos.com/calculator/l0nb1db6te | ||
return Math.cos(x - xOffset) + Math.cos(y - yOffset) + sizeValue > 1; | ||
} | ||
|
||
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++) { | ||
checkboxState = getCirclesCheckbox(x, y, elapsedTimeSeconds); | ||
newMatrix[y][x] = checkboxState ? 1 : 0; | ||
} | ||
} | ||
|
||
cbl.setData(newMatrix); | ||
|
||
timeoutId = setTimeout(loop, interval); | ||
} | ||
|
||
function cleanUp() { | ||
clearTimeout(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>Circles</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 circles from './demo.js'; | ||
circles.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