Skip to content

Commit

Permalink
Merge pull request #1 from szres/glyph-draw
Browse files Browse the repository at this point in the history
add glyph draw component
  • Loading branch information
Nigh committed Apr 4, 2024
2 parents bed6e9b + 82fcad0 commit 95f3864
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 10 deletions.
75 changes: 75 additions & 0 deletions src/routes/Glyph.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<script>
import { onMount } from 'svelte';
export let width = 64;
export let height = 64;
export let background = '#0000';
export let glyph = 'bmdkcl-';
let cx = width / 2;
let cy = height / 2;
let R = height / 2 - 2;
const glyphK1 = 0.76;
const glyphK2 = 0.38;
const glyphPoints = {
m: { dx: 0 * glyphK1, dy: -R * glyphK1 },
d: { dx: +Math.cos(Math.PI / 6) * R * glyphK1, dy: -Math.sin(Math.PI / 6) * R * glyphK1 },
k: { dx: +Math.cos(Math.PI / 6) * R * glyphK1, dy: Math.sin(Math.PI / 6) * R * glyphK1 },
c: { dx: 0 * glyphK1, dy: +R * glyphK1 },
l: { dx: -Math.cos(Math.PI / 6) * R * glyphK1, dy: Math.sin(Math.PI / 6) * R * glyphK1 },
b: { dx: -Math.cos(Math.PI / 6) * R * glyphK1, dy: -Math.sin(Math.PI / 6) * R * glyphK1 },
f: { dx: 0 * glyphK2, dy: -R * glyphK2 },
r: { dx: +Math.cos(Math.PI / 6) * R * glyphK2, dy: -Math.sin(Math.PI / 6) * R * glyphK2 },
j: { dx: +Math.cos(Math.PI / 6) * R * glyphK2, dy: Math.sin(Math.PI / 6) * R * glyphK2 },
p: { dx: 0 * glyphK2, dy: +R * glyphK2 },
h: { dx: -Math.cos(Math.PI / 6) * R * glyphK2, dy: Math.sin(Math.PI / 6) * R * glyphK2 },
t: { dx: -Math.cos(Math.PI / 6) * R * glyphK2, dy: -Math.sin(Math.PI / 6) * R * glyphK2 },
a: { dx: 0, dy: 0 }
};
let canvas;
let context;
onMount(() => {
context = canvas.getContext('2d');
context.lineWidth = 2;
context.strokeStyle = '#47df';
let hexagon = [
{ dx: 0, dy: -R },
{ dx: +Math.cos(Math.PI / 6) * R, dy: -Math.sin(Math.PI / 6) * R },
{ dx: +Math.cos(Math.PI / 6) * R, dy: Math.sin(Math.PI / 6) * R },
{ dx: 0, dy: +R },
{ dx: -Math.cos(Math.PI / 6) * R, dy: Math.sin(Math.PI / 6) * R },
{ dx: -Math.cos(Math.PI / 6) * R, dy: -Math.sin(Math.PI / 6) * R }
];
context.beginPath();
hexagon.forEach((point) => {
context.lineTo(cx + point.dx, cy + point.dy);
});
context.closePath();
context.stroke();
context.strokeStyle = '#ccc7';
context.lineWidth = 1;
for (const key in glyphPoints) {
context.beginPath();
context.arc(cx + glyphPoints[key].dx, cy + glyphPoints[key].dy, 1.4, 0, 2 * Math.PI);
context.closePath();
context.stroke();
}
context.strokeStyle = '#eee';
context.lineWidth = 2;
context.beginPath();
glyph.split('').forEach((g) => {
if (glyphPoints[g]) {
context.lineTo(cx + glyphPoints[g].dx, cy + glyphPoints[g].dy);
} else {
if (g === '-') {
context.closePath();
}
}
});
context.stroke();
});
</script>

<canvas {width} {height} style:background bind:this={canvas} />
14 changes: 9 additions & 5 deletions src/routes/normal.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<script>
import Glyph from './Glyph.svelte';
</script>

<div class="grid grid-flow-row gap-4 h-max m-4 justify-center content-center">
<ul class="steps">
<li data-content="" class="step step-success">FIELD</li>
<li data-content="" class="step step-success">TOGETHER</li>
<li data-content="" class="step step-success">IMPROVE</li>
<li data-content="?" class="step step-neutral">HUMAN</li>
<li data-content="?" class="step step-neutral">MIND</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="bhcjd-" />FIELD</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="lharta" />TOGETHER</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="jard" />IMPROVE</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="trjch-" />HUMAN</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="tach-" />MIND</li>
</ul>
</div>
14 changes: 9 additions & 5 deletions src/routes/overclock.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<script>
import Glyph from './Glyph.svelte';
</script>

<div class="grid grid-flow-row gap-4 h-max m-4 justify-center content-center">
<ul class="steps">
<li data-content="" class="step step-success">DEFEND</li>
<li data-content="" class="step step-success">HUMAN</li>
<li data-content="" class="step step-success">CIVILIZATION</li>
<li data-content="" class="step step-success">SHAPERS</li>
<li data-content="?" class="step step-neutral">LIE</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="bhcjd" />DEFEND</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="trjch-" />HUMAN</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="bthjrd" />CIVILIZATION</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="lhtmrjk" />SHAPERS</li>
<li data-content="?" class="step step-neutral"><Glyph glyph="htajra" />LIE</li>
</ul>
</div>

0 comments on commit 95f3864

Please sign in to comment.