Skip to content

Commit

Permalink
Converts to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
dzucconi committed May 29, 2021
1 parent c315016 commit 0583b61
Show file tree
Hide file tree
Showing 19 changed files with 6,110 additions and 218 deletions.
1 change: 0 additions & 1 deletion .babelrc

This file was deleted.

30 changes: 0 additions & 30 deletions .eslintrc.js

This file was deleted.

14 changes: 2 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Numerous always-ignore extensions
*.diff
*.err
*.orig
Expand All @@ -9,22 +8,13 @@
*.vi
*~
*.sass-cache

# OS or Editor folders
.DS_Store
.cache
.project
.settings
.tmproj
nbproject
Thumbs.db

# NPM packages folder.
node_modules/

# Brunch output folder.
public/

# Secrets
.env
.s3config
dist/
.parcel-cache/
3 changes: 0 additions & 3 deletions .s3config.sample

This file was deleted.

31 changes: 0 additions & 31 deletions app/assets/index.html

This file was deleted.

3 changes: 0 additions & 3 deletions app/initialize.js

This file was deleted.

68 changes: 0 additions & 68 deletions app/javascripts/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions app/javascripts/lib/rand.js

This file was deleted.

2 changes: 0 additions & 2 deletions app/javascripts/lib/uid.js

This file was deleted.

35 changes: 0 additions & 35 deletions brunch-config.js

This file was deleted.

29 changes: 5 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,14 @@
"url": "https://github.com/dzucconi/interpolated-sequence"
},
"scripts": {
"test": "mocha test",
"start": "brunch watch --server",
"prod": "brunch build --production",
"sync": "s3-cli --config .s3config sync --delete-removed --acl-public public/ s3://work.damonzucconi.com/$npm_package_name",
"deploy": "npm run prod && npm run sync"
"start": "parcel src/index.html --open",
"build": "parcel build src/index.html"
},
"devDependencies": {
"auto-reload-brunch": "^2.0.0",
"autoprefixer": "^6.5.0",
"babel-brunch": "~6.0.0",
"babel-core": "^6.17.0",
"babel-preset-es2015": "~6.3.13",
"brunch": "^2.4.0",
"clean-css-brunch": "^2.0.0",
"css-brunch": "^2.0.0",
"digest-brunch": "^1.6.0",
"eslint": "^3.7.1",
"javascript-brunch": "^2.0.0",
"mocha": "^3.1.0",
"postcss-brunch": "^2.0.3",
"s3-cli": "^0.13.0",
"should": "^11.1.0",
"uglify-js-brunch": "^2.0.0"
"parcel": "^2.0.0-beta.2"
},
"dependencies": {
"frame-interval": "0.0.1",
"pixi.js": "^4.3.0",
"queryparams": "0.0.6"
"frame-interval": "1.0.47",
"queryparams": "1.2.2"
}
}
File renamed without changes.
27 changes: 27 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="author" value="Damon Zucconi" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta
name="viewport"
content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi"
/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

<title>Interpolated Sequence</title>

<link rel="stylesheet" type="text/css" href="./index.css" />
</head>
<body>
<div id="root" class="app"></div>

<script src="./javascripts/index.ts"></script>

<script>
// TODO
</script>
</body>
</html>
75 changes: 75 additions & 0 deletions src/javascripts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { FrameInterval } from "frame-interval";
import { configure } from "queryparams";
import { uid } from "./lib/uid";
import { rand } from "./lib/rand";
import { tag } from "./lib/dom";

const DOM = {
app: document.getElementById("root"),
};

const STATE: Record<string, number> = {};

const creator =
(size: number) =>
(n: number, randomize: boolean): [string, CanvasRenderingContext2D] => {
const id = `canvas_${uid()}`;

const node = tag(
"div",
{ klass: "container" },
` <canvas id='${id}' width='${n}' height='${n}'></canvas>
`
);

if (size) {
node.style.width = `${size}px`;
node.style.height = `${size}px`;
}

DOM.app.appendChild(node);

DOM[id] = document.getElementById(id);
STATE[id] = randomize ? rand(-1, 9) : -1;

const ctx = (DOM[id] as HTMLCanvasElement).getContext("2d");

ctx.font = `${n}px 'Helvetica Neue', sans-serif`;
ctx.fillStyle = "white";
ctx.textBaseline = "middle";
ctx.textAlign = "center";

return [id, ctx];
};

const update = ([id, ctx]: [string, CanvasRenderingContext2D]) => {
if (STATE[id] === 9) STATE[id] = 0;

STATE[id]++;

ctx.clearRect(0, 0, DOM[id].width, DOM[id].height);
ctx.fillText(String(STATE[id]), DOM[id].width / 2, DOM[id].height / 2);
};

const { params } = configure({
fps: 60,
amount: 10,
offset: 1,
step: 1,
randomize: false,
});

const create = creator(
Math.min(window.innerWidth / params.amount, window.innerHeight)
);

const handles = Array(params.amount)
.fill(undefined)
.map((_, n) => {
const step = n === 0 ? 1 : params.step;
return create((n + params.offset) * step, params.randomize);
});

const fi = new FrameInterval(params.fps, () => handles.forEach(update));

fi.start();
7 changes: 5 additions & 2 deletions app/javascripts/lib/dom.js → src/javascripts/lib/dom.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export const tag = (type, { id, klass } = {}, html) => {
export const tag = (
type: string,
{ id, klass }: { id?: string; klass?: string } = {},
html?: string
) => {
const el = document.createElement(type);

if (id) el.id = id;
if (klass) el.className = klass;

if (html) el.innerHTML = html;

return el;
Expand Down
2 changes: 2 additions & 0 deletions src/javascripts/lib/rand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const rand = (min: number, max: number) =>
Math.floor(Math.random() * (max - min) + min);
2 changes: 2 additions & 0 deletions src/javascripts/lib/uid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const uid = () =>
("0000" + ((Math.random() * Math.pow(36, 4)) << 0).toString(36)).slice(-4);
5 changes: 0 additions & 5 deletions test/mocha.opts

This file was deleted.

Loading

0 comments on commit 0583b61

Please sign in to comment.