headreel 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/assets/fonts/Caveat.ttf +0 -0
- package/assets/fonts/OFL-Caveat.txt +93 -0
- package/dist/cli/run.js +2 -2
- package/dist/core/data/now-playing.js +282 -0
- package/dist/core/fonts.js +3 -0
- package/dist/styles/index.js +2 -0
- package/dist/styles/now-playing/deck.js +105 -0
- package/dist/styles/now-playing/index.js +16 -0
- package/dist/styles/now-playing/options.js +19 -0
- package/dist/styles/now-playing/palette.js +69 -0
- package/dist/styles/now-playing/sketch.js +610 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,6 +120,18 @@ Set the style with `style: <name>` in the Action, or `--style <name>` in the com
|
|
|
120
120
|
| `theme` | `light` | `light` or `dark`. Use `dark` if your profile is mostly viewed in GitHub dark mode. |
|
|
121
121
|
| `accent` | `cobalt` | Color of the bars, numbers and links: `cobalt`, `green`, `violet`, `orange` or `pink`. |
|
|
122
122
|
|
|
123
|
+
### Now Playing
|
|
124
|
+
|
|
125
|
+
`now-playing`: a cassette deck playing the repository you committed to most in the last 30 days. The label names its language, your commit messages on it scroll across the deck's display as lyrics, and the level meter shows the month day by day. When nothing was committed in the last 30 days, the deck shows the repository you pushed to last as `LAST PLAYED`.
|
|
126
|
+
|
|
127
|
+

|
|
128
|
+
|
|
129
|
+
| Option | Default | Description |
|
|
130
|
+
| --------- | ------- | --------------------------------------------------------------------------------------------------- |
|
|
131
|
+
| `theme` | `dark` | `dark` (graphite deck) or `light` (silver deck). |
|
|
132
|
+
| `accent` | `cyan` | Display color, meter and links: `cyan`, `green` or `orange`. |
|
|
133
|
+
| `exclude` | empty | Comma-separated repositories never picked, for example your profile repository: `exclude: octocat`. |
|
|
134
|
+
|
|
123
135
|
### Repo Galaxy
|
|
124
136
|
|
|
125
137
|
`repo-galaxy`: your most starred repositories orbit a sun. A bigger planet has more stars, and its color is the repository's main language. Repositories you pushed to recently orbit closer to the sun.
|
|
Binary file
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2014 The Caveat Project Authors (https://github.com/googlefonts/caveat)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
package/dist/cli/run.js
CHANGED
|
@@ -24,7 +24,7 @@ async function render(settings, io) {
|
|
|
24
24
|
throw new Error(`Output must be a .gif file, got "${settings.out}".`);
|
|
25
25
|
}
|
|
26
26
|
// Fail on bad options before any API call.
|
|
27
|
-
parseOptions(style, settings.options);
|
|
27
|
+
const options = parseOptions(style, settings.options);
|
|
28
28
|
let login;
|
|
29
29
|
let name;
|
|
30
30
|
let data;
|
|
@@ -38,7 +38,7 @@ async function render(settings, io) {
|
|
|
38
38
|
const user = settings.user;
|
|
39
39
|
const [profile, fetched] = await Promise.all([
|
|
40
40
|
fetchProfile(client, user),
|
|
41
|
-
style.data.fetch(client, user, io.now()),
|
|
41
|
+
style.data.fetch(client, user, io.now(), options),
|
|
42
42
|
]);
|
|
43
43
|
({ login, name } = profile);
|
|
44
44
|
data = fetched;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// The tape is the user's most active public repository of the last 30 days.
|
|
3
|
+
// Two queries when something is playing; a third one finds the fallback.
|
|
4
|
+
// Query 1: every repository the user committed to in the window, with its
|
|
5
|
+
// daily commit counts. The user's id feeds the author filter of query 2.
|
|
6
|
+
const QUERY = /* GraphQL */ `
|
|
7
|
+
query NowPlaying($login: String!, $from: DateTime!, $to: DateTime!) {
|
|
8
|
+
user(login: $login) {
|
|
9
|
+
id
|
|
10
|
+
contributionsCollection(from: $from, to: $to) {
|
|
11
|
+
commitContributionsByRepository(maxRepositories: 25) {
|
|
12
|
+
repository {
|
|
13
|
+
name
|
|
14
|
+
owner {
|
|
15
|
+
login
|
|
16
|
+
}
|
|
17
|
+
isPrivate
|
|
18
|
+
primaryLanguage {
|
|
19
|
+
name
|
|
20
|
+
color
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
contributions(first: 31) {
|
|
24
|
+
totalCount
|
|
25
|
+
nodes {
|
|
26
|
+
occurredAt
|
|
27
|
+
commitCount
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
// Query 2: the playing repository's default-branch commits authored by the
|
|
36
|
+
// user since the window started. GitHub counts commit contributions on the
|
|
37
|
+
// default branch (or gh-pages) only, the same source as query 1.
|
|
38
|
+
const COMMIT_HISTORY = /* GraphQL */ `
|
|
39
|
+
edges {
|
|
40
|
+
node {
|
|
41
|
+
messageHeadline
|
|
42
|
+
parents {
|
|
43
|
+
totalCount
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const COMMITS_QUERY = /* GraphQL */ `
|
|
49
|
+
query NowPlayingCommits($owner: String!, $name: String!, $id: ID!, $since: GitTimestamp!) {
|
|
50
|
+
repository(owner: $owner, name: $name) {
|
|
51
|
+
defaultBranchRef {
|
|
52
|
+
target {
|
|
53
|
+
... on Commit {
|
|
54
|
+
history(author: { id: $id }, since: $since, first: 30) {
|
|
55
|
+
${COMMIT_HISTORY}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
// Fallback: the most recently pushed owned public repository and the user's
|
|
64
|
+
// latest commits on it, without `since`. The history rides on every node, so
|
|
65
|
+
// one query covers whichever repository the picker lands on.
|
|
66
|
+
const FALLBACK_QUERY = /* GraphQL */ `
|
|
67
|
+
query NowPlayingFallback($login: String!, $id: ID!, $first: Int!) {
|
|
68
|
+
user(login: $login) {
|
|
69
|
+
repositories(
|
|
70
|
+
first: $first
|
|
71
|
+
ownerAffiliations: OWNER
|
|
72
|
+
privacy: PUBLIC
|
|
73
|
+
isFork: false
|
|
74
|
+
orderBy: { field: PUSHED_AT, direction: DESC }
|
|
75
|
+
) {
|
|
76
|
+
nodes {
|
|
77
|
+
name
|
|
78
|
+
owner {
|
|
79
|
+
login
|
|
80
|
+
}
|
|
81
|
+
primaryLanguage {
|
|
82
|
+
name
|
|
83
|
+
color
|
|
84
|
+
}
|
|
85
|
+
defaultBranchRef {
|
|
86
|
+
target {
|
|
87
|
+
... on Commit {
|
|
88
|
+
history(author: { id: $id }, first: 30) {
|
|
89
|
+
${COMMIT_HISTORY}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
export const WINDOW_DAYS = 30;
|
|
100
|
+
export const statusSchema = z.enum(['playing', 'last-played', 'empty']);
|
|
101
|
+
const languageSchema = z
|
|
102
|
+
.object({
|
|
103
|
+
name: z.string().min(1),
|
|
104
|
+
/** Linguist color; null when the repo has no language or color. */
|
|
105
|
+
color: z
|
|
106
|
+
.string()
|
|
107
|
+
.regex(/^#[0-9a-fA-F]{6}$/)
|
|
108
|
+
.nullable(),
|
|
109
|
+
})
|
|
110
|
+
.nullable();
|
|
111
|
+
export const nowPlayingSchema = z.object({
|
|
112
|
+
/** Fetch date, YYYY-MM-DD (UTC). */
|
|
113
|
+
asOf: z.iso.date(),
|
|
114
|
+
status: statusSchema,
|
|
115
|
+
repo: z
|
|
116
|
+
.object({
|
|
117
|
+
/** Not always the user: contributions to another user's project show as owner/name. */
|
|
118
|
+
owner: z.string().min(1),
|
|
119
|
+
name: z.string().min(1),
|
|
120
|
+
language: languageSchema,
|
|
121
|
+
})
|
|
122
|
+
.nullable(),
|
|
123
|
+
/** The playing repo's commits in the window; 0 on fallback. */
|
|
124
|
+
commits: z.number().int().min(0),
|
|
125
|
+
/** Its part of all public commits in the window, 0..1. */
|
|
126
|
+
share: z.number().min(0).max(1),
|
|
127
|
+
/** The playing repo's daily commits in the window, oldest first. */
|
|
128
|
+
days: z.array(z.number().int().min(0)).length(WINDOW_DAYS),
|
|
129
|
+
/** The repo's default-branch commit headlines, newest first, merges dropped. */
|
|
130
|
+
lyrics: z.array(z.string().min(1)).max(8),
|
|
131
|
+
});
|
|
132
|
+
const DAY_MS = 86_400_000;
|
|
133
|
+
/**
|
|
134
|
+
* The 30 days ending on `now` (UTC): `from` is 29 days back at midnight, `to`
|
|
135
|
+
* is today, matching the run date the banner is rendered on.
|
|
136
|
+
*/
|
|
137
|
+
export function nowPlayingWindow(now) {
|
|
138
|
+
const today = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
|
|
139
|
+
return {
|
|
140
|
+
from: new Date(today - (WINDOW_DAYS - 1) * DAY_MS).toISOString().slice(0, 10),
|
|
141
|
+
to: new Date(today).toISOString().slice(0, 10),
|
|
142
|
+
asOf: new Date(today).toISOString().slice(0, 10),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The daily commit counts of one repository across the window, oldest first.
|
|
147
|
+
* `occurredAt` days outside the window are dropped.
|
|
148
|
+
*/
|
|
149
|
+
export function windowDays(contributions, from, to) {
|
|
150
|
+
const counts = new Map();
|
|
151
|
+
for (const node of contributions.nodes ?? []) {
|
|
152
|
+
counts.set(node.occurredAt.slice(0, 10), (counts.get(node.occurredAt.slice(0, 10)) ?? 0) + node.commitCount);
|
|
153
|
+
}
|
|
154
|
+
const days = [];
|
|
155
|
+
for (let t = Date.parse(`${from}T00:00:00Z`); t <= Date.parse(`${to}T00:00:00Z`); t += DAY_MS) {
|
|
156
|
+
days.push(counts.get(new Date(t).toISOString().slice(0, 10)) ?? 0);
|
|
157
|
+
}
|
|
158
|
+
return days;
|
|
159
|
+
}
|
|
160
|
+
/** Index of the last day with a commit, -1 when the repository had none. */
|
|
161
|
+
function lastActiveIndex(days) {
|
|
162
|
+
for (let i = days.length - 1; i >= 0; i--) {
|
|
163
|
+
if (days[i] > 0)
|
|
164
|
+
return i;
|
|
165
|
+
}
|
|
166
|
+
return -1;
|
|
167
|
+
}
|
|
168
|
+
function excludedBy(exclude) {
|
|
169
|
+
const names = new Set(exclude.map((n) => n.trim().toLowerCase()));
|
|
170
|
+
return (owner, name) => names.has(name.toLowerCase()) || names.has(`${owner}/${name}`.toLowerCase());
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Drops excluded names, then picks the playing one: most commits in the
|
|
174
|
+
* window, ties to the latest active day, then name.
|
|
175
|
+
*/
|
|
176
|
+
export function pickRepo(candidates, exclude = []) {
|
|
177
|
+
const isExcluded = excludedBy(exclude);
|
|
178
|
+
let best = null;
|
|
179
|
+
for (const c of candidates) {
|
|
180
|
+
if (isExcluded(c.owner, c.name))
|
|
181
|
+
continue;
|
|
182
|
+
if (!best || better(c, best))
|
|
183
|
+
best = c;
|
|
184
|
+
}
|
|
185
|
+
return best;
|
|
186
|
+
}
|
|
187
|
+
function better(a, b) {
|
|
188
|
+
if (a.commits !== b.commits)
|
|
189
|
+
return a.commits > b.commits;
|
|
190
|
+
const ai = lastActiveIndex(a.days);
|
|
191
|
+
const bi = lastActiveIndex(b.days);
|
|
192
|
+
if (ai !== bi)
|
|
193
|
+
return ai > bi;
|
|
194
|
+
return a.name.localeCompare(b.name) < 0;
|
|
195
|
+
}
|
|
196
|
+
/** Merges (more than one parent) and empty headlines never become lyrics. */
|
|
197
|
+
export function lyricsFromHistory(nodes) {
|
|
198
|
+
return nodes
|
|
199
|
+
.filter((n) => n.parents.totalCount <= 1 && n.messageHeadline.trim().length > 0)
|
|
200
|
+
.map((n) => n.messageHeadline.trim())
|
|
201
|
+
.slice(0, 8);
|
|
202
|
+
}
|
|
203
|
+
const ZEROS = Array.from({ length: WINDOW_DAYS }).fill(0);
|
|
204
|
+
export async function fetchNowPlaying(client, login, now, options = {}) {
|
|
205
|
+
const { from, to, asOf } = nowPlayingWindow(now);
|
|
206
|
+
const since = `${from}T00:00:00Z`;
|
|
207
|
+
const { user } = await client(QUERY, {
|
|
208
|
+
login,
|
|
209
|
+
from: since,
|
|
210
|
+
to: `${to}T23:59:59Z`,
|
|
211
|
+
});
|
|
212
|
+
// Private repositories are dropped before anything is picked: repo names
|
|
213
|
+
// and commit messages of private repos never reach the banner.
|
|
214
|
+
const candidates = user.contributionsCollection.commitContributionsByRepository
|
|
215
|
+
.filter((entry) => !entry.repository.isPrivate)
|
|
216
|
+
.map((entry) => ({
|
|
217
|
+
owner: entry.repository.owner.login,
|
|
218
|
+
name: entry.repository.name,
|
|
219
|
+
commits: entry.contributions.totalCount,
|
|
220
|
+
days: windowDays(entry.contributions, from, to),
|
|
221
|
+
language: entry.repository.primaryLanguage
|
|
222
|
+
? {
|
|
223
|
+
name: entry.repository.primaryLanguage.name,
|
|
224
|
+
color: entry.repository.primaryLanguage.color,
|
|
225
|
+
}
|
|
226
|
+
: null,
|
|
227
|
+
}));
|
|
228
|
+
const picked = pickRepo(candidates, options.exclude ?? []);
|
|
229
|
+
if (picked) {
|
|
230
|
+
const all = candidates.reduce((sum, c) => sum + c.commits, 0);
|
|
231
|
+
const { repository } = await client(COMMITS_QUERY, {
|
|
232
|
+
owner: picked.owner,
|
|
233
|
+
name: picked.name,
|
|
234
|
+
id: user.id,
|
|
235
|
+
since,
|
|
236
|
+
});
|
|
237
|
+
return {
|
|
238
|
+
asOf,
|
|
239
|
+
status: 'playing',
|
|
240
|
+
repo: { owner: picked.owner, name: picked.name, language: picked.language },
|
|
241
|
+
commits: picked.commits,
|
|
242
|
+
share: all > 0 ? picked.commits / all : 0,
|
|
243
|
+
days: picked.days,
|
|
244
|
+
lyrics: lyricsFromHistory(repository?.defaultBranchRef?.target?.history?.edges.map((e) => e.node) ?? []),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
// Nothing playing: the most recently pushed owned public repository, whose
|
|
248
|
+
// latest default-branch commits become the lyrics without a window.
|
|
249
|
+
const fallback = await client(FALLBACK_QUERY, {
|
|
250
|
+
login,
|
|
251
|
+
id: user.id,
|
|
252
|
+
first: 25,
|
|
253
|
+
});
|
|
254
|
+
const isExcluded = excludedBy(options.exclude ?? []);
|
|
255
|
+
const repo = fallback.user.repositories.nodes.find((n) => !isExcluded(n.owner.login, n.name));
|
|
256
|
+
if (!repo) {
|
|
257
|
+
return {
|
|
258
|
+
asOf,
|
|
259
|
+
status: 'empty',
|
|
260
|
+
repo: null,
|
|
261
|
+
commits: 0,
|
|
262
|
+
share: 0,
|
|
263
|
+
days: [...ZEROS],
|
|
264
|
+
lyrics: [],
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
asOf,
|
|
269
|
+
status: 'last-played',
|
|
270
|
+
repo: {
|
|
271
|
+
owner: repo.owner.login,
|
|
272
|
+
name: repo.name,
|
|
273
|
+
language: repo.primaryLanguage
|
|
274
|
+
? { name: repo.primaryLanguage.name, color: repo.primaryLanguage.color }
|
|
275
|
+
: null,
|
|
276
|
+
},
|
|
277
|
+
commits: 0,
|
|
278
|
+
share: 0,
|
|
279
|
+
days: [...ZEROS],
|
|
280
|
+
lyrics: lyricsFromHistory(repo.defaultBranchRef?.target?.history?.edges.map((e) => e.node) ?? []),
|
|
281
|
+
};
|
|
282
|
+
}
|
package/dist/core/fonts.js
CHANGED
|
@@ -5,6 +5,9 @@ const FONT_FILES = [
|
|
|
5
5
|
'SpaceGrotesk-Medium.ttf',
|
|
6
6
|
'SpaceGrotesk-Bold.ttf',
|
|
7
7
|
'JetBrainsMono-Regular.ttf',
|
|
8
|
+
// Handwriting face for Now Playing's cassette label. Variable font: Skia
|
|
9
|
+
// registers the default 400 instance and ignores other weights.
|
|
10
|
+
'Caveat.ttf',
|
|
8
11
|
];
|
|
9
12
|
// Resolves from both src/core (tsx, vitest) and dist/core (published build).
|
|
10
13
|
const FONT_DIR = new URL('../../assets/fonts/', import.meta.url);
|
package/dist/styles/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { contributionCity } from './contribution-city/index.js';
|
|
2
2
|
import { highlightsReel } from './highlights-reel/index.js';
|
|
3
|
+
import { nowPlaying } from './now-playing/index.js';
|
|
3
4
|
import { repoGalaxy } from './repo-galaxy/index.js';
|
|
4
5
|
/** Built-in styles, keyed by id. */
|
|
5
6
|
export const styles = {
|
|
6
7
|
[contributionCity.id]: contributionCity,
|
|
7
8
|
[highlightsReel.id]: highlightsReel,
|
|
9
|
+
[nowPlaying.id]: nowPlaying,
|
|
8
10
|
[repoGalaxy.id]: repoGalaxy,
|
|
9
11
|
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { paletteOf } from './palette.js';
|
|
2
|
+
/** 8 lyric lines at 2 s each, at 25 fps. */
|
|
3
|
+
export const FRAMES = 400;
|
|
4
|
+
/** Cassette hub and the fullest tape pack, px. */
|
|
5
|
+
export const HUB_R = 26;
|
|
6
|
+
export const PACK_MAX = 40;
|
|
7
|
+
const COUNTER_MAX = 999;
|
|
8
|
+
function hexToRgb(hex) {
|
|
9
|
+
const n = Number.parseInt(hex.slice(1), 16);
|
|
10
|
+
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
11
|
+
}
|
|
12
|
+
function rgbToHsl([r, g, b]) {
|
|
13
|
+
const [rn, gn, bn] = [r / 255, g / 255, b / 255];
|
|
14
|
+
const max = Math.max(rn, gn, bn);
|
|
15
|
+
const min = Math.min(rn, gn, bn);
|
|
16
|
+
const l = (max + min) / 2;
|
|
17
|
+
if (max === min)
|
|
18
|
+
return [0, 0, l];
|
|
19
|
+
const d = max - min;
|
|
20
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
21
|
+
let h;
|
|
22
|
+
if (max === rn)
|
|
23
|
+
h = ((gn - bn) / d + (gn < bn ? 6 : 0)) / 6;
|
|
24
|
+
else if (max === gn)
|
|
25
|
+
h = ((bn - rn) / d + 2) / 6;
|
|
26
|
+
else
|
|
27
|
+
h = ((rn - gn) / d + 4) / 6;
|
|
28
|
+
return [h, s, l];
|
|
29
|
+
}
|
|
30
|
+
function hslToRgb(h, s, l) {
|
|
31
|
+
if (s === 0) {
|
|
32
|
+
const v = Math.round(l * 255);
|
|
33
|
+
return [v, v, v];
|
|
34
|
+
}
|
|
35
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
36
|
+
const p = 2 * l - q;
|
|
37
|
+
const channel = (t) => {
|
|
38
|
+
if (t < 0)
|
|
39
|
+
t += 1;
|
|
40
|
+
if (t > 1)
|
|
41
|
+
t -= 1;
|
|
42
|
+
if (t < 1 / 6)
|
|
43
|
+
return p + (q - p) * 6 * t;
|
|
44
|
+
if (t < 1 / 2)
|
|
45
|
+
return q;
|
|
46
|
+
if (t < 2 / 3)
|
|
47
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
48
|
+
return p;
|
|
49
|
+
};
|
|
50
|
+
return [
|
|
51
|
+
Math.round(channel(h + 1 / 3) * 255),
|
|
52
|
+
Math.round(channel(h) * 255),
|
|
53
|
+
Math.round(channel(h - 1 / 3) * 255),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The band's caption is small white type, so the band is held to a darkness
|
|
58
|
+
* pale linguist colors reach after adjustment and dark ones keep their hue.
|
|
59
|
+
*/
|
|
60
|
+
export function languageBandColor(hex) {
|
|
61
|
+
if (!hex)
|
|
62
|
+
return [90, 96, 110];
|
|
63
|
+
const [h, s, l] = rgbToHsl(hexToRgb(hex));
|
|
64
|
+
return hslToRgb(h, Math.min(s, 0.8), Math.min(Math.max(l, 0.3), 0.45));
|
|
65
|
+
}
|
|
66
|
+
/** Tape pack radius for a share of the tape, by area. */
|
|
67
|
+
export function packRadius(share) {
|
|
68
|
+
const s = Math.min(1, Math.max(0, share));
|
|
69
|
+
return Math.sqrt(HUB_R ** 2 + s * (PACK_MAX ** 2 - HUB_R ** 2));
|
|
70
|
+
}
|
|
71
|
+
function reel(share, phase) {
|
|
72
|
+
const radius = packRadius(share);
|
|
73
|
+
return { radius, revs: Math.max(1, Math.round(80 / radius)), phase };
|
|
74
|
+
}
|
|
75
|
+
/** Meter heights: sqrt scaling, so a quiet day next to a busy one still shows. */
|
|
76
|
+
export function meterBars(days) {
|
|
77
|
+
const max = Math.max(1, ...days);
|
|
78
|
+
return days.map((c) => (c > 0 ? Math.sqrt(c / max) : 0));
|
|
79
|
+
}
|
|
80
|
+
export function buildDeck(data, options, rng) {
|
|
81
|
+
const brush = [];
|
|
82
|
+
for (let i = 0; i < 90; i++) {
|
|
83
|
+
brush.push({
|
|
84
|
+
y: rng(),
|
|
85
|
+
x0: rng() * 0.6,
|
|
86
|
+
x1: 0.4 + rng() * 0.6,
|
|
87
|
+
alpha: 0.03 + rng() * 0.03,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
palette: paletteOf(options),
|
|
92
|
+
status: data.status,
|
|
93
|
+
repo: data.repo ? { owner: data.repo.owner, name: data.repo.name } : null,
|
|
94
|
+
bandColor: languageBandColor(data.repo?.language?.color),
|
|
95
|
+
languageName: data.repo?.language?.name ?? null,
|
|
96
|
+
counter: Math.min(COUNTER_MAX, data.commits),
|
|
97
|
+
bars: meterBars(data.days),
|
|
98
|
+
lyrics: data.lyrics,
|
|
99
|
+
takeUp: reel(data.share, rng()),
|
|
100
|
+
supply: reel(1 - data.share, rng()),
|
|
101
|
+
brush,
|
|
102
|
+
screws: [rng() * Math.PI, rng() * Math.PI, rng() * Math.PI, rng() * Math.PI],
|
|
103
|
+
labelTilt: (rng() - 0.5) * 0.04,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fetchNowPlaying, nowPlayingSchema } from '../../core/data/now-playing.js';
|
|
2
|
+
import { buildDeck, FRAMES } from './deck.js';
|
|
3
|
+
import { options } from './options.js';
|
|
4
|
+
import { paletteOf, pinnedOf } from './palette.js';
|
|
5
|
+
import { createDeckSketch } from './sketch.js';
|
|
6
|
+
export const nowPlaying = {
|
|
7
|
+
id: 'now-playing',
|
|
8
|
+
fps: 25,
|
|
9
|
+
frames: FRAMES,
|
|
10
|
+
pinned: (options) => pinnedOf(paletteOf(options)),
|
|
11
|
+
data: { name: 'nowplaying', schema: nowPlayingSchema, fetch: fetchNowPlaying },
|
|
12
|
+
options,
|
|
13
|
+
createSketch({ data, options, identity, rng }) {
|
|
14
|
+
return createDeckSketch(buildDeck(data, options, rng), identity);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const THEMES = ['dark', 'light'];
|
|
3
|
+
export const ACCENTS = ['cyan', 'green', 'orange'];
|
|
4
|
+
export const options = z
|
|
5
|
+
.object({
|
|
6
|
+
/** The deck and the room: graphite on dark, or a silver deck on light. */
|
|
7
|
+
theme: z.enum(THEMES).default('dark'),
|
|
8
|
+
/** Display phosphor, level meter, play LED, prompt and links. Real VFD colors only. */
|
|
9
|
+
accent: z.enum(ACCENTS).default('cyan'),
|
|
10
|
+
/** Comma-separated repositories never picked, e.g. the profile repo itself. */
|
|
11
|
+
exclude: z
|
|
12
|
+
.string()
|
|
13
|
+
.default('')
|
|
14
|
+
.transform((v) => v
|
|
15
|
+
.split(',')
|
|
16
|
+
.map((n) => n.trim())
|
|
17
|
+
.filter(Boolean)),
|
|
18
|
+
})
|
|
19
|
+
.strict();
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accent presets: the three colors real VFDs came in. The phosphor value
|
|
3
|
+
* passes 4.5:1 on the display glass; the light theme's darker value passes
|
|
4
|
+
* 4.5:1 on its room (both asserted by a test).
|
|
5
|
+
*/
|
|
6
|
+
export const ACCENT_VALUES = {
|
|
7
|
+
cyan: [34, 211, 238],
|
|
8
|
+
green: [52, 211, 153],
|
|
9
|
+
orange: [251, 146, 60],
|
|
10
|
+
};
|
|
11
|
+
/** Tailwind 700 of each accent (orange 800: 700 misses 4.5:1), for type on the light room. */
|
|
12
|
+
const LIGHT_ACCENT_VALUES = {
|
|
13
|
+
cyan: [14, 116, 144],
|
|
14
|
+
green: [4, 120, 87],
|
|
15
|
+
orange: [154, 52, 18],
|
|
16
|
+
};
|
|
17
|
+
const CASSETTE = {
|
|
18
|
+
shell: [46, 44, 41],
|
|
19
|
+
tape: [24, 19, 17],
|
|
20
|
+
paper: [239, 230, 210],
|
|
21
|
+
ink: [31, 29, 26],
|
|
22
|
+
glass: [7, 16, 15],
|
|
23
|
+
amber: [255, 181, 71],
|
|
24
|
+
red: [255, 77, 61],
|
|
25
|
+
};
|
|
26
|
+
const BASE = {
|
|
27
|
+
dark: {
|
|
28
|
+
...CASSETTE,
|
|
29
|
+
bg: [16, 17, 20],
|
|
30
|
+
vignette: 0.3,
|
|
31
|
+
faceplate: [36, 38, 43],
|
|
32
|
+
bevel: [58, 61, 68],
|
|
33
|
+
keyTop: [58, 61, 68],
|
|
34
|
+
keyRim: [255, 255, 255],
|
|
35
|
+
screw: [22, 23, 26],
|
|
36
|
+
plateInk: [143, 147, 156],
|
|
37
|
+
identityInk: [242, 239, 232],
|
|
38
|
+
identityMuted: [143, 147, 156],
|
|
39
|
+
},
|
|
40
|
+
// A silver deck, as 1980s hi-fi came in. The window and display stay dark.
|
|
41
|
+
light: {
|
|
42
|
+
...CASSETTE,
|
|
43
|
+
bg: [236, 237, 241],
|
|
44
|
+
vignette: 0.06,
|
|
45
|
+
faceplate: [204, 207, 212],
|
|
46
|
+
bevel: [246, 247, 249],
|
|
47
|
+
keyTop: [226, 228, 232],
|
|
48
|
+
keyRim: [255, 255, 255],
|
|
49
|
+
screw: [120, 124, 132],
|
|
50
|
+
plateInk: [70, 74, 82],
|
|
51
|
+
identityInk: [17, 18, 22],
|
|
52
|
+
identityMuted: [92, 96, 106],
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
export function paletteOf(options) {
|
|
56
|
+
const accent = ACCENT_VALUES[options.accent];
|
|
57
|
+
return {
|
|
58
|
+
...BASE[options.theme],
|
|
59
|
+
accent,
|
|
60
|
+
identityAccent: options.theme === 'dark' ? accent : LIGHT_ACCENT_VALUES[options.accent],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Flat colors the encoder keeps exact and undithered. */
|
|
64
|
+
export function pinnedOf(palette) {
|
|
65
|
+
const colors = [palette.bg, palette.faceplate, palette.glass, palette.paper, palette.accent];
|
|
66
|
+
if (palette.identityAccent !== palette.accent)
|
|
67
|
+
colors.push(palette.identityAccent);
|
|
68
|
+
return colors;
|
|
69
|
+
}
|
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import { canvasMeasure, fitIdentity, fitLine, } from '../../core/text.js';
|
|
2
|
+
import { HUB_R } from './deck.js';
|
|
3
|
+
/**
|
|
4
|
+
* A cassette deck, drawn as hardware: the cassette through a smoked window,
|
|
5
|
+
* a VFD showing the user's commit messages as lyrics, and a level meter of
|
|
6
|
+
* the month's days.
|
|
7
|
+
*
|
|
8
|
+
* Everything is drawn through the raw 2D context with the style set right
|
|
9
|
+
* before each draw (see Highlights Reel's note on p5's cached fill state).
|
|
10
|
+
* The chrome is one static layer built in setup; the reels, the display and
|
|
11
|
+
* the LEDs animate over it. Every animated value is periodic in `t`.
|
|
12
|
+
*/
|
|
13
|
+
const SANS = '"Space Grotesk"';
|
|
14
|
+
const MONO = '"JetBrains Mono"';
|
|
15
|
+
const HAND = '"Caveat"';
|
|
16
|
+
/**
|
|
17
|
+
* The prompt names what the tape is with made-up flags: the most active repo
|
|
18
|
+
* of the window, or the last pushed one when the window was empty.
|
|
19
|
+
*/
|
|
20
|
+
export function promptFor(status) {
|
|
21
|
+
if (status === 'playing')
|
|
22
|
+
return '~/now-playing --most-active-repo --30d';
|
|
23
|
+
if (status === 'last-played')
|
|
24
|
+
return '~/now-playing --last-pushed';
|
|
25
|
+
return '~/now-playing';
|
|
26
|
+
}
|
|
27
|
+
const W = 1280;
|
|
28
|
+
const H = 400;
|
|
29
|
+
const TAU = Math.PI * 2;
|
|
30
|
+
/** Width of the identity column: x 48 to 420. */
|
|
31
|
+
export const IDENTITY_COLUMN = 420 - 48;
|
|
32
|
+
const PLATE = { x: 452, y: 36, w: 784, h: 328, r: 12 };
|
|
33
|
+
/** The smoked window and its interior, where the cassette sits. */
|
|
34
|
+
const WELL = { x: 470, y: 56, w: 304, h: 190, r: 8 };
|
|
35
|
+
const INTERIOR = { x: WELL.x + 7, y: WELL.y + 7, w: WELL.w - 14, h: WELL.h - 14, r: 5 };
|
|
36
|
+
const CASSETTE = { x: 486, y: 72, w: 272, h: 160, r: 6 };
|
|
37
|
+
const LABEL = { x: 500, y: 82, w: 244, h: 58 };
|
|
38
|
+
const BAND_H = 20;
|
|
39
|
+
const HUBS = { y: 192, left: 548, right: 696 };
|
|
40
|
+
const KEYS = ['REW', 'PLAY', 'FF', 'STOP', 'REC'];
|
|
41
|
+
const KEY = { w: 52, h: 44, gap: 9, y: 264 };
|
|
42
|
+
const DISPLAY = { x: 792, y: 56, w: 428, h: 240, r: 8 };
|
|
43
|
+
const PAD = 18;
|
|
44
|
+
const UX = DISPLAY.x + PAD;
|
|
45
|
+
const UW = DISPLAY.w - PAD * 2;
|
|
46
|
+
const LYRIC_BASE = [128, 158, 188];
|
|
47
|
+
const LYRIC_ROW = 30;
|
|
48
|
+
const METER = { y: 210, h: 62 };
|
|
49
|
+
const BARS = 30;
|
|
50
|
+
const COUNTER = { x: 792, y: 308, w: 112, h: 40 };
|
|
51
|
+
const LEDS = { rec: 934, play: 988, y: 328 };
|
|
52
|
+
const clamp01 = (v) => Math.min(1, Math.max(0, v));
|
|
53
|
+
/** 0..1, periodic in `t`, so every animated value loops seamlessly. */
|
|
54
|
+
function wave(t, cycles, off) {
|
|
55
|
+
return 0.5 + 0.5 * Math.sin(TAU * (t * cycles + off));
|
|
56
|
+
}
|
|
57
|
+
/** The tape scroll: a short eased move between holds. */
|
|
58
|
+
function easeInOut(t) {
|
|
59
|
+
return t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2;
|
|
60
|
+
}
|
|
61
|
+
function rgba(color, alpha = 1) {
|
|
62
|
+
return `rgba(${color[0]},${color[1]},${color[2]},${alpha})`;
|
|
63
|
+
}
|
|
64
|
+
function setFill(ctx, color, alpha = 1) {
|
|
65
|
+
ctx.fillStyle = rgba(color, alpha);
|
|
66
|
+
}
|
|
67
|
+
function setStroke(ctx, color, alpha = 1) {
|
|
68
|
+
ctx.strokeStyle = rgba(color, alpha);
|
|
69
|
+
}
|
|
70
|
+
function setFont(ctx, o) {
|
|
71
|
+
ctx.font = `${o.bold ? 700 : 400} ${o.size}px ${o.mono ? MONO : (o.family ?? SANS)}`;
|
|
72
|
+
ctx.textAlign = o.align ?? 'left';
|
|
73
|
+
ctx.textBaseline = 'alphabetic';
|
|
74
|
+
ctx.letterSpacing = `${o.tracking ?? 0}px`;
|
|
75
|
+
}
|
|
76
|
+
function drawText(ctx, str, x, y, o) {
|
|
77
|
+
setFont(ctx, o);
|
|
78
|
+
setFill(ctx, o.color, o.alpha ?? 1);
|
|
79
|
+
ctx.fillText(str, x, y);
|
|
80
|
+
if (o.tracking)
|
|
81
|
+
ctx.letterSpacing = '0px';
|
|
82
|
+
}
|
|
83
|
+
/** Phosphor: the glyphs carry a faint glow, as a VFD does. */
|
|
84
|
+
function glowText(ctx, str, x, y, o) {
|
|
85
|
+
setFont(ctx, o);
|
|
86
|
+
setFill(ctx, o.color, o.alpha ?? 1);
|
|
87
|
+
ctx.shadowColor = rgba(o.color, 0.9);
|
|
88
|
+
ctx.shadowBlur = o.glow ?? 7;
|
|
89
|
+
ctx.fillText(str, x, y);
|
|
90
|
+
ctx.shadowBlur = 0;
|
|
91
|
+
ctx.shadowColor = 'transparent';
|
|
92
|
+
if (o.tracking)
|
|
93
|
+
ctx.letterSpacing = '0px';
|
|
94
|
+
}
|
|
95
|
+
function measure(ctx, str, o) {
|
|
96
|
+
setFont(ctx, o);
|
|
97
|
+
return ctx.measureText(str).width;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* The lyric lines on the display at `t`: index into the lyrics, baseline and
|
|
101
|
+
* alpha. Lines scroll up one row between holds; the middle one is bright, its
|
|
102
|
+
* neighbours dim, and the loop wraps from the last line to the first. The row
|
|
103
|
+
* two below the middle is hidden during a hold and scrolls in, so no line
|
|
104
|
+
* appears in place. With two lines, the row above would repeat the row below,
|
|
105
|
+
* so it is left out and the leaving line fades out on its way up.
|
|
106
|
+
*/
|
|
107
|
+
export function lyricLayout(n, t) {
|
|
108
|
+
if (n === 0)
|
|
109
|
+
return [];
|
|
110
|
+
if (n === 1)
|
|
111
|
+
return [{ index: 0, base: LYRIC_BASE[1], alpha: 1 }];
|
|
112
|
+
const u = t * n;
|
|
113
|
+
const k = Math.floor(u) % n;
|
|
114
|
+
const offset = easeInOut(clamp01((u - Math.floor(u) - 0.8) / 0.2));
|
|
115
|
+
const rows = n === 2 ? [0, 1, 2] : [-1, 0, 1, 2];
|
|
116
|
+
const fadeAbove = n === 2 ? 1 : 0.68;
|
|
117
|
+
const lines = [];
|
|
118
|
+
for (const row of rows) {
|
|
119
|
+
const base = LYRIC_BASE[1] + (row - offset) * LYRIC_ROW;
|
|
120
|
+
const dist = Math.abs(base - LYRIC_BASE[1]) / LYRIC_ROW;
|
|
121
|
+
const alpha = clamp01(1 - dist * (base < LYRIC_BASE[1] ? fadeAbove : 0.68));
|
|
122
|
+
if (alpha > 0.02)
|
|
123
|
+
lines.push({ index: (k + row + n) % n, base, alpha });
|
|
124
|
+
}
|
|
125
|
+
return lines;
|
|
126
|
+
}
|
|
127
|
+
/** Width the hand-written name may take on the label. */
|
|
128
|
+
export const TAPE_NAME_WIDTH = LABEL.w - 24;
|
|
129
|
+
/**
|
|
130
|
+
* The hand-written `owner/name` on the label, with baselines relative to the
|
|
131
|
+
* label's writing area. One line when it fits at 20 px or more; otherwise the
|
|
132
|
+
* owner goes on a smaller first line and the name below it, each cut with an
|
|
133
|
+
* ellipsis if it is still too long.
|
|
134
|
+
*/
|
|
135
|
+
export function tapeLabel(owner, name, measure) {
|
|
136
|
+
const full = `${owner}/${name}`;
|
|
137
|
+
if (measure(full, 20) <= TAPE_NAME_WIDTH) {
|
|
138
|
+
return [{ ...fitLine(full, TAPE_NAME_WIDTH, 30, 20, measure), dy: 0 }];
|
|
139
|
+
}
|
|
140
|
+
return [
|
|
141
|
+
{ ...fitLine(`${owner}/`, TAPE_NAME_WIDTH, 16, 16, measure), dy: -16 },
|
|
142
|
+
{ ...fitLine(name, TAPE_NAME_WIDTH, 22, 18, measure), dy: 2 },
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
function roundRect(ctx, x, y, w, h, r) {
|
|
146
|
+
ctx.beginPath();
|
|
147
|
+
ctx.roundRect(x, y, w, h, r);
|
|
148
|
+
}
|
|
149
|
+
export function createDeckSketch(deck, identity) {
|
|
150
|
+
const P = deck.palette;
|
|
151
|
+
const prompt = promptFor(deck.status);
|
|
152
|
+
const fitted = fitIdentity({
|
|
153
|
+
name: identity.name.toUpperCase(),
|
|
154
|
+
tagline: identity.tagline,
|
|
155
|
+
website: identity.website && `↗ ${displayUrl(identity.website)}`,
|
|
156
|
+
}, IDENTITY_COLUMN);
|
|
157
|
+
const repo = deck.repo;
|
|
158
|
+
// Lines are cut with an ellipsis at the width they are drawn into.
|
|
159
|
+
const measureMono = canvasMeasure('JetBrains Mono', 400);
|
|
160
|
+
const measureHand = canvasMeasure('Caveat', 400);
|
|
161
|
+
const topLabel = deck.status === 'last-played' ? 'LAST PLAYED' : 'NOW PLAYING';
|
|
162
|
+
const topLabelW = canvasMeasure('JetBrains Mono', 400, 2)(topLabel, 12);
|
|
163
|
+
const topName =
|
|
164
|
+
// The label carries the owner; the display keeps the room for the name.
|
|
165
|
+
repo === null ? null : fitLine(repo.name, UW - topLabelW - 14, 13, 13, measureMono);
|
|
166
|
+
const lyrics = deck.lyrics.map((line) => fitLine(line, UW, 14, 14, measureMono));
|
|
167
|
+
const tapeName = repo === null ? [] : tapeLabel(repo.owner, repo.name, measureHand);
|
|
168
|
+
const languageName = deck.languageName === null
|
|
169
|
+
? null
|
|
170
|
+
: fitLine(deck.languageName, LABEL.w * 0.55, 8, 8, canvasMeasure('JetBrains Mono', 400, 1));
|
|
171
|
+
// --- static layer ---------------------------------------------------------
|
|
172
|
+
function drawVignette(ctx) {
|
|
173
|
+
const grad = ctx.createRadialGradient(W / 2, H / 2 - 20, 180, W / 2, H / 2, 860);
|
|
174
|
+
grad.addColorStop(0, 'rgba(0,0,0,0)');
|
|
175
|
+
grad.addColorStop(1, `rgba(0,0,0,${P.vignette})`);
|
|
176
|
+
ctx.fillStyle = grad;
|
|
177
|
+
ctx.fillRect(0, 0, W, H);
|
|
178
|
+
}
|
|
179
|
+
function drawPlate(ctx) {
|
|
180
|
+
setFill(ctx, P.faceplate);
|
|
181
|
+
roundRect(ctx, PLATE.x, PLATE.y, PLATE.w, PLATE.h, PLATE.r);
|
|
182
|
+
ctx.fill();
|
|
183
|
+
// Fine horizontal brushing, seeded.
|
|
184
|
+
for (const s of deck.brush) {
|
|
185
|
+
setStroke(ctx, [255, 255, 255], s.alpha);
|
|
186
|
+
ctx.lineWidth = 1;
|
|
187
|
+
ctx.beginPath();
|
|
188
|
+
ctx.moveTo(PLATE.x + 4 + s.x0 * (PLATE.w - 8), PLATE.y + 4 + s.y * (PLATE.h - 8));
|
|
189
|
+
ctx.lineTo(PLATE.x + 4 + s.x1 * (PLATE.w - 8), PLATE.y + 4 + s.y * (PLATE.h - 8));
|
|
190
|
+
ctx.stroke();
|
|
191
|
+
}
|
|
192
|
+
// Bevel: light on top, dark on the bottom edge.
|
|
193
|
+
setStroke(ctx, P.bevel, 0.65);
|
|
194
|
+
ctx.lineWidth = 1.5;
|
|
195
|
+
ctx.beginPath();
|
|
196
|
+
ctx.moveTo(PLATE.x + PLATE.r, PLATE.y + 1);
|
|
197
|
+
ctx.lineTo(PLATE.x + PLATE.w - PLATE.r, PLATE.y + 1);
|
|
198
|
+
ctx.stroke();
|
|
199
|
+
setStroke(ctx, [0, 0, 0], 0.4);
|
|
200
|
+
ctx.beginPath();
|
|
201
|
+
ctx.moveTo(PLATE.x + PLATE.r, PLATE.y + PLATE.h - 1);
|
|
202
|
+
ctx.lineTo(PLATE.x + PLATE.w - PLATE.r, PLATE.y + PLATE.h - 1);
|
|
203
|
+
ctx.stroke();
|
|
204
|
+
setStroke(ctx, [0, 0, 0], 0.35);
|
|
205
|
+
ctx.lineWidth = 1;
|
|
206
|
+
roundRect(ctx, PLATE.x + 0.5, PLATE.y + 0.5, PLATE.w - 1, PLATE.h - 1, PLATE.r);
|
|
207
|
+
ctx.stroke();
|
|
208
|
+
// Screws in the corners, slots at seeded angles.
|
|
209
|
+
const corners = [
|
|
210
|
+
[PLATE.x + 16, PLATE.y + 16],
|
|
211
|
+
[PLATE.x + PLATE.w - 16, PLATE.y + 16],
|
|
212
|
+
[PLATE.x + 16, PLATE.y + PLATE.h - 16],
|
|
213
|
+
[PLATE.x + PLATE.w - 16, PLATE.y + PLATE.h - 16],
|
|
214
|
+
];
|
|
215
|
+
corners.forEach(([cx, cy], i) => {
|
|
216
|
+
setFill(ctx, P.screw);
|
|
217
|
+
ctx.beginPath();
|
|
218
|
+
ctx.arc(cx, cy, 4.5, 0, TAU);
|
|
219
|
+
ctx.fill();
|
|
220
|
+
setStroke(ctx, P.bevel, 0.9);
|
|
221
|
+
ctx.lineWidth = 1.5;
|
|
222
|
+
const a = deck.screws[i];
|
|
223
|
+
ctx.beginPath();
|
|
224
|
+
ctx.moveTo(cx - Math.cos(a) * 3, cy - Math.sin(a) * 3);
|
|
225
|
+
ctx.lineTo(cx + Math.cos(a) * 3, cy + Math.sin(a) * 3);
|
|
226
|
+
ctx.stroke();
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function drawWellChrome(ctx) {
|
|
230
|
+
// The well's interior: glass over the faceplate, the cassette sits inside.
|
|
231
|
+
setFill(ctx, P.glass, 0.85);
|
|
232
|
+
roundRect(ctx, INTERIOR.x, INTERIOR.y, INTERIOR.w, INTERIOR.h, INTERIOR.r);
|
|
233
|
+
ctx.fill();
|
|
234
|
+
setStroke(ctx, P.bevel, 0.9);
|
|
235
|
+
ctx.lineWidth = 1.5;
|
|
236
|
+
roundRect(ctx, WELL.x, WELL.y, WELL.w, WELL.h, WELL.r);
|
|
237
|
+
ctx.stroke();
|
|
238
|
+
setStroke(ctx, [0, 0, 0], 0.5);
|
|
239
|
+
ctx.lineWidth = 1;
|
|
240
|
+
roundRect(ctx, INTERIOR.x + 0.5, INTERIOR.y + 0.5, INTERIOR.w - 1, INTERIOR.h - 1, INTERIOR.r);
|
|
241
|
+
ctx.stroke();
|
|
242
|
+
}
|
|
243
|
+
function drawDisplayChrome(ctx) {
|
|
244
|
+
setFill(ctx, P.glass);
|
|
245
|
+
roundRect(ctx, DISPLAY.x, DISPLAY.y, DISPLAY.w, DISPLAY.h, DISPLAY.r);
|
|
246
|
+
ctx.fill();
|
|
247
|
+
setStroke(ctx, P.bevel, 0.9);
|
|
248
|
+
ctx.lineWidth = 1.5;
|
|
249
|
+
roundRect(ctx, DISPLAY.x, DISPLAY.y, DISPLAY.w, DISPLAY.h, DISPLAY.r);
|
|
250
|
+
ctx.stroke();
|
|
251
|
+
setStroke(ctx, [0, 0, 0], 0.5);
|
|
252
|
+
ctx.lineWidth = 1;
|
|
253
|
+
roundRect(ctx, DISPLAY.x + 1, DISPLAY.y + 1, DISPLAY.w - 2, DISPLAY.h - 2, DISPLAY.r - 1);
|
|
254
|
+
ctx.stroke();
|
|
255
|
+
// Unlit segment ghosts, as real VFDs show.
|
|
256
|
+
const ghost = rgba(P.accent, 0.05);
|
|
257
|
+
ctx.fillStyle = ghost;
|
|
258
|
+
for (const base of LYRIC_BASE) {
|
|
259
|
+
for (let x = UX; x < UX + UW - 3; x += 7) {
|
|
260
|
+
ctx.fillRect(x, base - 9, 3.5, 10);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function drawKeys(ctx) {
|
|
265
|
+
const total = KEYS.length * KEY.w + (KEYS.length - 1) * KEY.gap;
|
|
266
|
+
const x0 = WELL.x + (WELL.w - total) / 2;
|
|
267
|
+
KEYS.forEach((label, i) => {
|
|
268
|
+
const pressed = label === 'PLAY';
|
|
269
|
+
const x = x0 + i * (KEY.w + KEY.gap);
|
|
270
|
+
const y = KEY.y + (pressed ? 5 : 0);
|
|
271
|
+
const h = KEY.h - (pressed ? 5 : 0);
|
|
272
|
+
// Slot the raised keys sit out of.
|
|
273
|
+
if (!pressed) {
|
|
274
|
+
setFill(ctx, [0, 0, 0], 0.35);
|
|
275
|
+
roundRect(ctx, x, KEY.y - 3, KEY.w, KEY.h + 3, 5);
|
|
276
|
+
ctx.fill();
|
|
277
|
+
}
|
|
278
|
+
setFill(ctx, pressed ? P.faceplate : P.keyTop);
|
|
279
|
+
roundRect(ctx, x, y, KEY.w, h, 5);
|
|
280
|
+
ctx.fill();
|
|
281
|
+
setStroke(ctx, pressed ? [0, 0, 0] : P.keyRim, pressed ? 0.4 : 0.25);
|
|
282
|
+
ctx.lineWidth = 1;
|
|
283
|
+
roundRect(ctx, x + 0.5, y + 0.5, KEY.w - 1, h - 1, 5);
|
|
284
|
+
ctx.stroke();
|
|
285
|
+
if (pressed) {
|
|
286
|
+
setFill(ctx, P.identityAccent, 0.9);
|
|
287
|
+
ctx.fillRect(x + 8, y + 4, KEY.w - 16, 2.5);
|
|
288
|
+
}
|
|
289
|
+
drawText(ctx, label, x + KEY.w / 2, KEY.y + KEY.h + 18, {
|
|
290
|
+
size: 10,
|
|
291
|
+
align: 'center',
|
|
292
|
+
color: P.plateInk,
|
|
293
|
+
alpha: pressed ? 0.9 : 0.6,
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
function drawCounter(ctx) {
|
|
298
|
+
setFill(ctx, [10, 11, 14]);
|
|
299
|
+
roundRect(ctx, COUNTER.x, COUNTER.y, COUNTER.w, COUNTER.h, 4);
|
|
300
|
+
ctx.fill();
|
|
301
|
+
setStroke(ctx, P.bevel, 0.8);
|
|
302
|
+
ctx.lineWidth = 1;
|
|
303
|
+
roundRect(ctx, COUNTER.x + 0.5, COUNTER.y + 0.5, COUNTER.w - 1, COUNTER.h - 1, 4);
|
|
304
|
+
ctx.stroke();
|
|
305
|
+
const digits = String(deck.counter).padStart(3, '0');
|
|
306
|
+
for (let i = 0; i < 3; i++) {
|
|
307
|
+
const x = COUNTER.x + 10 + i * 33;
|
|
308
|
+
setFill(ctx, [4, 4, 6]);
|
|
309
|
+
roundRect(ctx, x, COUNTER.y + 7, 28, 26, 2);
|
|
310
|
+
ctx.fill();
|
|
311
|
+
drawText(ctx, digits[i], x + 14, COUNTER.y + 28, {
|
|
312
|
+
size: 19,
|
|
313
|
+
mono: true,
|
|
314
|
+
bold: true,
|
|
315
|
+
align: 'center',
|
|
316
|
+
color: P.amber,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
drawText(ctx, 'COUNTER', COUNTER.x + COUNTER.w / 2, COUNTER.y + COUNTER.h + 12, {
|
|
320
|
+
size: 7,
|
|
321
|
+
mono: true,
|
|
322
|
+
tracking: 2,
|
|
323
|
+
align: 'center',
|
|
324
|
+
color: P.plateInk,
|
|
325
|
+
alpha: 0.7,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
function drawLedLabels(ctx) {
|
|
329
|
+
drawText(ctx, 'REC', LEDS.rec + 9, LEDS.y + 3, {
|
|
330
|
+
size: 7,
|
|
331
|
+
mono: true,
|
|
332
|
+
color: P.plateInk,
|
|
333
|
+
alpha: 0.7,
|
|
334
|
+
});
|
|
335
|
+
drawText(ctx, 'PLAY', LEDS.play + 9, LEDS.y + 3, {
|
|
336
|
+
size: 7,
|
|
337
|
+
mono: true,
|
|
338
|
+
color: P.plateInk,
|
|
339
|
+
alpha: 0.7,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function drawIdentity(ctx) {
|
|
343
|
+
const x = 48;
|
|
344
|
+
drawText(ctx, prompt, x, 58, { size: 13, mono: true, color: P.identityAccent });
|
|
345
|
+
drawText(ctx, fitted.name.text, x, 116, {
|
|
346
|
+
size: fitted.name.size,
|
|
347
|
+
bold: true,
|
|
348
|
+
color: P.identityInk,
|
|
349
|
+
tracking: 3,
|
|
350
|
+
});
|
|
351
|
+
if (fitted.tagline) {
|
|
352
|
+
drawText(ctx, fitted.tagline.text, x, 146, {
|
|
353
|
+
size: fitted.tagline.size,
|
|
354
|
+
color: P.identityAccent,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
if (fitted.website) {
|
|
358
|
+
drawText(ctx, fitted.website.text, x, 350, {
|
|
359
|
+
size: fitted.website.size,
|
|
360
|
+
mono: true,
|
|
361
|
+
color: P.identityAccent,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
let chrome;
|
|
366
|
+
function setup(p) {
|
|
367
|
+
chrome = p.createGraphics(W, H);
|
|
368
|
+
const ctx = chrome.drawingContext;
|
|
369
|
+
setFill(ctx, P.bg);
|
|
370
|
+
ctx.fillRect(0, 0, W, H);
|
|
371
|
+
drawVignette(ctx);
|
|
372
|
+
drawPlate(ctx);
|
|
373
|
+
drawWellChrome(ctx);
|
|
374
|
+
drawDisplayChrome(ctx);
|
|
375
|
+
drawKeys(ctx);
|
|
376
|
+
drawCounter(ctx);
|
|
377
|
+
drawLedLabels(ctx);
|
|
378
|
+
drawIdentity(ctx);
|
|
379
|
+
}
|
|
380
|
+
// --- cassette -------------------------------------------------------------
|
|
381
|
+
function drawReel(ctx, reel, cx, t) {
|
|
382
|
+
const angle = (reel.phase + reel.revs * t) * TAU;
|
|
383
|
+
setFill(ctx, P.tape);
|
|
384
|
+
ctx.beginPath();
|
|
385
|
+
ctx.arc(cx, HUBS.y, reel.radius, 0, TAU);
|
|
386
|
+
ctx.fill();
|
|
387
|
+
// Wound tape: a bright rim and faint rings.
|
|
388
|
+
if (reel.radius > HUB_R + 2) {
|
|
389
|
+
setStroke(ctx, [96, 84, 72], 0.55);
|
|
390
|
+
ctx.lineWidth = 1;
|
|
391
|
+
ctx.beginPath();
|
|
392
|
+
ctx.arc(cx, HUBS.y, reel.radius - 0.5, 0, TAU);
|
|
393
|
+
ctx.stroke();
|
|
394
|
+
setStroke(ctx, [255, 255, 255], 0.05);
|
|
395
|
+
for (let r = HUB_R + 5; r < reel.radius - 2; r += 4) {
|
|
396
|
+
ctx.beginPath();
|
|
397
|
+
ctx.arc(cx, HUBS.y, r, 0, TAU);
|
|
398
|
+
ctx.stroke();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
// Six-spoke hub, turning a whole number of sixths per loop.
|
|
402
|
+
setStroke(ctx, [92, 86, 78], 0.95);
|
|
403
|
+
ctx.lineWidth = 5;
|
|
404
|
+
ctx.lineCap = 'round';
|
|
405
|
+
ctx.beginPath();
|
|
406
|
+
for (let i = 0; i < 3; i++) {
|
|
407
|
+
const a = angle + (i * TAU) / 6;
|
|
408
|
+
const dx = Math.cos(a) * (HUB_R - 3);
|
|
409
|
+
const dy = Math.sin(a) * (HUB_R - 3);
|
|
410
|
+
ctx.moveTo(cx - dx, HUBS.y - dy);
|
|
411
|
+
ctx.lineTo(cx + dx, HUBS.y + dy);
|
|
412
|
+
}
|
|
413
|
+
ctx.stroke();
|
|
414
|
+
ctx.lineCap = 'butt';
|
|
415
|
+
setFill(ctx, P.tape);
|
|
416
|
+
ctx.beginPath();
|
|
417
|
+
ctx.arc(cx, HUBS.y, 5, 0, TAU);
|
|
418
|
+
ctx.fill();
|
|
419
|
+
}
|
|
420
|
+
function drawCassette(ctx, t) {
|
|
421
|
+
ctx.save();
|
|
422
|
+
roundRect(ctx, INTERIOR.x, INTERIOR.y, INTERIOR.w, INTERIOR.h, INTERIOR.r);
|
|
423
|
+
ctx.clip();
|
|
424
|
+
if (deck.status !== 'empty') {
|
|
425
|
+
setFill(ctx, P.shell);
|
|
426
|
+
roundRect(ctx, CASSETTE.x, CASSETTE.y, CASSETTE.w, CASSETTE.h, CASSETTE.r);
|
|
427
|
+
ctx.fill();
|
|
428
|
+
setStroke(ctx, [255, 255, 255], 0.06);
|
|
429
|
+
ctx.lineWidth = 1;
|
|
430
|
+
ctx.beginPath();
|
|
431
|
+
ctx.moveTo(CASSETTE.x + CASSETTE.r, CASSETTE.y + 1);
|
|
432
|
+
ctx.lineTo(CASSETTE.x + CASSETTE.w - CASSETTE.r, CASSETTE.y + 1);
|
|
433
|
+
ctx.stroke();
|
|
434
|
+
setStroke(ctx, [20, 19, 17], 0.8);
|
|
435
|
+
roundRect(ctx, CASSETTE.x + 0.5, CASSETTE.y + 0.5, CASSETTE.w - 1, CASSETTE.h - 1, CASSETTE.r);
|
|
436
|
+
ctx.stroke();
|
|
437
|
+
// Label: cream paper, colored band, hand-written name.
|
|
438
|
+
setFill(ctx, P.paper);
|
|
439
|
+
ctx.fillRect(LABEL.x, LABEL.y, LABEL.w, LABEL.h);
|
|
440
|
+
setFill(ctx, deck.bandColor);
|
|
441
|
+
ctx.fillRect(LABEL.x, LABEL.y, LABEL.w, BAND_H);
|
|
442
|
+
setStroke(ctx, [0, 0, 0], 0.15);
|
|
443
|
+
ctx.lineWidth = 1;
|
|
444
|
+
ctx.strokeRect(LABEL.x + 0.5, LABEL.y + 0.5, LABEL.w - 1, LABEL.h - 1);
|
|
445
|
+
drawText(ctx, 'SIDE A', LABEL.x + 7, LABEL.y + 14, {
|
|
446
|
+
size: 8,
|
|
447
|
+
mono: true,
|
|
448
|
+
tracking: 1,
|
|
449
|
+
color: [255, 255, 255],
|
|
450
|
+
alpha: 0.92,
|
|
451
|
+
});
|
|
452
|
+
if (languageName) {
|
|
453
|
+
drawText(ctx, languageName.text, LABEL.x + LABEL.w - 7, LABEL.y + 14, {
|
|
454
|
+
size: languageName.size,
|
|
455
|
+
mono: true,
|
|
456
|
+
tracking: 1,
|
|
457
|
+
align: 'right',
|
|
458
|
+
color: [255, 255, 255],
|
|
459
|
+
alpha: 0.92,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
ctx.save();
|
|
463
|
+
ctx.translate(LABEL.x + LABEL.w / 2, LABEL.y + BAND_H + (LABEL.h - BAND_H) / 2 + 12);
|
|
464
|
+
ctx.rotate(deck.labelTilt);
|
|
465
|
+
for (const line of tapeName) {
|
|
466
|
+
drawText(ctx, line.text, 0, line.dy, {
|
|
467
|
+
size: line.size,
|
|
468
|
+
family: HAND,
|
|
469
|
+
align: 'center',
|
|
470
|
+
color: P.ink,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
ctx.restore();
|
|
474
|
+
// Tape threading along the bottom, then the reels.
|
|
475
|
+
setFill(ctx, P.tape);
|
|
476
|
+
ctx.fillRect(HUBS.left, 216, HUBS.right - HUBS.left, 3);
|
|
477
|
+
drawReel(ctx, deck.supply, HUBS.left, t);
|
|
478
|
+
drawReel(ctx, deck.takeUp, HUBS.right, t);
|
|
479
|
+
}
|
|
480
|
+
// Smoked glass over whatever is inside.
|
|
481
|
+
setFill(ctx, P.glass, 0.35);
|
|
482
|
+
ctx.fillRect(INTERIOR.x, INTERIOR.y, INTERIOR.w, INTERIOR.h);
|
|
483
|
+
ctx.restore();
|
|
484
|
+
}
|
|
485
|
+
// --- display --------------------------------------------------------------
|
|
486
|
+
function drawLyrics(ctx, t) {
|
|
487
|
+
ctx.save();
|
|
488
|
+
roundRect(ctx, DISPLAY.x + 4, DISPLAY.y + 4, DISPLAY.w - 8, DISPLAY.h - 8, DISPLAY.r - 2);
|
|
489
|
+
ctx.clip();
|
|
490
|
+
for (const { index, base, alpha } of lyricLayout(lyrics.length, t)) {
|
|
491
|
+
const line = lyrics[index];
|
|
492
|
+
const opts = { size: line.size, mono: true, color: P.accent, alpha };
|
|
493
|
+
if (alpha > 0.8) {
|
|
494
|
+
glowText(ctx, line.text, UX, base, opts);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
drawText(ctx, line.text, UX, base, opts);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
ctx.restore();
|
|
501
|
+
}
|
|
502
|
+
function drawMeter(ctx, t) {
|
|
503
|
+
const pitch = UW / BARS;
|
|
504
|
+
const barW = pitch * 0.55;
|
|
505
|
+
const pos = (t * BARS) % BARS;
|
|
506
|
+
deck.bars.forEach((height, i) => {
|
|
507
|
+
const x = UX + i * pitch + (pitch - barW) / 2;
|
|
508
|
+
if (height <= 0) {
|
|
509
|
+
// Unlit ghost for a day without commits.
|
|
510
|
+
setFill(ctx, P.accent, 0.09);
|
|
511
|
+
ctx.fillRect(x, METER.y, barW, METER.h);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
const d = (pos - i + BARS) % BARS;
|
|
515
|
+
const flash = Math.exp(-d * 0.4);
|
|
516
|
+
setFill(ctx, P.accent, Math.min(1, 0.55 + flash * 0.45));
|
|
517
|
+
const h = Math.max(3, height * METER.h);
|
|
518
|
+
ctx.fillRect(x, METER.y + METER.h - h, barW, h);
|
|
519
|
+
});
|
|
520
|
+
setStroke(ctx, P.accent, 0.25);
|
|
521
|
+
ctx.lineWidth = 1;
|
|
522
|
+
ctx.beginPath();
|
|
523
|
+
ctx.moveTo(UX, METER.y + METER.h + 2.5);
|
|
524
|
+
ctx.lineTo(UX + UW, METER.y + METER.h + 2.5);
|
|
525
|
+
ctx.stroke();
|
|
526
|
+
// The playhead sweeps once per loop.
|
|
527
|
+
const px = UX + pos * pitch + pitch / 2;
|
|
528
|
+
ctx.save();
|
|
529
|
+
setStroke(ctx, P.accent, 0.55);
|
|
530
|
+
ctx.lineWidth = 1.5;
|
|
531
|
+
ctx.shadowColor = rgba(P.accent, 0.9);
|
|
532
|
+
ctx.shadowBlur = 6;
|
|
533
|
+
ctx.beginPath();
|
|
534
|
+
ctx.moveTo(px, METER.y - 4);
|
|
535
|
+
ctx.lineTo(px, METER.y + METER.h + 4);
|
|
536
|
+
ctx.stroke();
|
|
537
|
+
ctx.restore();
|
|
538
|
+
ctx.shadowBlur = 0;
|
|
539
|
+
ctx.shadowColor = 'transparent';
|
|
540
|
+
}
|
|
541
|
+
function drawDisplay(ctx, t) {
|
|
542
|
+
if (deck.status === 'empty') {
|
|
543
|
+
glowText(ctx, 'NO TAPE', UX, 86, {
|
|
544
|
+
size: 13,
|
|
545
|
+
mono: true,
|
|
546
|
+
tracking: 2,
|
|
547
|
+
color: P.accent,
|
|
548
|
+
alpha: 0.85,
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
drawText(ctx, topLabel, UX, 86, {
|
|
553
|
+
size: 12,
|
|
554
|
+
mono: true,
|
|
555
|
+
tracking: 2,
|
|
556
|
+
color: P.accent,
|
|
557
|
+
alpha: 0.55,
|
|
558
|
+
});
|
|
559
|
+
if (topName) {
|
|
560
|
+
glowText(ctx, topName.text, UX + topLabelW + 14, 86, {
|
|
561
|
+
size: topName.size,
|
|
562
|
+
mono: true,
|
|
563
|
+
color: P.accent,
|
|
564
|
+
alpha: 0.95,
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
drawLyrics(ctx, t);
|
|
569
|
+
drawMeter(ctx, t);
|
|
570
|
+
}
|
|
571
|
+
function drawLeds(ctx, t) {
|
|
572
|
+
// Record-off: the red LED stays dim. Play pulses once per loop.
|
|
573
|
+
setFill(ctx, P.red, 0.22);
|
|
574
|
+
ctx.beginPath();
|
|
575
|
+
ctx.arc(LEDS.rec, LEDS.y, 4.5, 0, TAU);
|
|
576
|
+
ctx.fill();
|
|
577
|
+
const pulse = 0.45 + 0.55 * wave(t, 1, 0);
|
|
578
|
+
ctx.save();
|
|
579
|
+
setFill(ctx, P.accent, pulse);
|
|
580
|
+
ctx.shadowColor = rgba(P.accent, pulse);
|
|
581
|
+
ctx.shadowBlur = 8;
|
|
582
|
+
ctx.beginPath();
|
|
583
|
+
ctx.arc(LEDS.play, LEDS.y, 4.5, 0, TAU);
|
|
584
|
+
ctx.fill();
|
|
585
|
+
ctx.restore();
|
|
586
|
+
ctx.shadowBlur = 0;
|
|
587
|
+
ctx.shadowColor = 'transparent';
|
|
588
|
+
}
|
|
589
|
+
function drawCursor(ctx, t) {
|
|
590
|
+
// Once a second, a terminal's blink rate: 16 whole cycles per 16 s loop.
|
|
591
|
+
if (wave(t, 16, 0) <= 0.5)
|
|
592
|
+
return;
|
|
593
|
+
setFill(ctx, P.identityAccent);
|
|
594
|
+
ctx.fillRect(48 + measure(ctx, prompt, { size: 13, mono: true }) + 4, 47, 7, 13);
|
|
595
|
+
}
|
|
596
|
+
function draw(p, _frame, t) {
|
|
597
|
+
const ctx = p.drawingContext;
|
|
598
|
+
if (chrome)
|
|
599
|
+
p.image(chrome, 0, 0);
|
|
600
|
+
drawCassette(ctx, t);
|
|
601
|
+
drawDisplay(ctx, t);
|
|
602
|
+
drawLeds(ctx, t);
|
|
603
|
+
drawCursor(ctx, t);
|
|
604
|
+
}
|
|
605
|
+
return { setup, draw };
|
|
606
|
+
}
|
|
607
|
+
/** "https://www.example.com/" -> "www.example.com" */
|
|
608
|
+
function displayUrl(url) {
|
|
609
|
+
return url.replace(/^[a-z]+:\/\//i, '').replace(/\/+$/, '');
|
|
610
|
+
}
|