This commit is contained in:
Amelia Cuss 2022-01-05 15:55:18 +11:00
commit 8ac4a1c616
8 changed files with 5411 additions and 0 deletions

26
.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
/dist
/.cache
# misc
./**/.DS_Store
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

3
.sassrc Normal file
View File

@ -0,0 +1,3 @@
{
"includePaths": ["node_modules"],
}

15
package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "hotcrossbun",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"build": "parcel build ./src/index.html --out-dir build",
"start": "tsc --noEmit --watch & parcel ./src/index.html"
},
"devDependencies": {
"@types/node": "^14.14.19",
"parcel-bundler": "^1.12.4",
"sass": "^1.32.0",
"typescript": "^4.1.3"
}
}

13
src/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>hot cross bun</title>
<link rel="stylesheet" href="./styles/global.scss" />
</head>
<body>
<canvas></canvas>
</body>
<script src="main.ts"></script>
</html>

64
src/main.ts Normal file
View File

@ -0,0 +1,64 @@
let canvas = document.querySelector("canvas") as HTMLCanvasElement;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let ctx = canvas.getContext("2d") as CanvasRenderingContext2D;
interface Puzzle {
palette: Record<string, string>,
width: number,
height: number,
pixels: number[][],
};
const puzzle: Puzzle = {
palette: {
1: 'darkgreen',
2: 'grey',
3: 'black',
4: 'pink',
},
width: 10,
height: 5,
pixels: [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 2, 1, 2, 1, 2, 2, 2, 1, 1],
[1, 2, 2, 2, 2, 2, 2, 2, 2, 1],
[1, 3, 2, 3, 2, 2, 2, 2, 2, 4],
[2, 2, 2, 2, 2, 4, 4, 4, 4, 4],
],
};
function drawPuzzle(puzzle: Puzzle): void {
for (let y = 0; y < puzzle.height; y++) {
for (let x = 0; x < puzzle.width; x++) {
ctx.fillStyle = puzzle.palette[puzzle.pixels[y][x]];
ctx.fillRect(x * 10, y * 10, 10, 10);
}
}
}
let mouse = {
x: 0,
y: 0,
};
window.addEventListener("mousemove", (e) => {
mouse.x = e.x;
mouse.y = e.y;
});
window.addEventListener("resize", () => {
canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
});
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, window.innerWidth, window.innerHeight);
drawPuzzle(puzzle);
}
animate();
export {}

4
src/styles/global.scss Normal file
View File

@ -0,0 +1,4 @@
* {
margin: 0;
padding: 0 !important;
}

23
tsconfig.json Normal file
View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"~/*": ["./*"]
},
"typeRoots": ["node_modules/@types"],
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "build"]
}

5263
yarn.lock Normal file

File diff suppressed because it is too large Load Diff