This repository was archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFactory.html
137 lines (118 loc) · 4.34 KB
/
Factory.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="author" content="jspenguin2017" />
<title>Icon Factory</title>
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<style>
/* Debug scalling */
:root {
--scale: 1;
}
</style>
<script>
const scale = getComputedStyle(document.documentElement).getPropertyValue("--scale");
</script>
</head>
<body style="background-color:ghostwhite;">
<p id="mousePos" style="position:absolute; left:calc(var(--scale) * 128px + 40px); top:8px; margin:0;">(0, 0)</p>
<canvas height="128" width="128" style="width:calc(var(--scale) * 128px); height:calc(var(--scale) * 128px); image-rendering:pixelated;"></canvas>
<script>
const canvas = document.querySelector("canvas");
const context = canvas.getContext("2d");
{
// Show coordinate on mouse move
let locked = false;
const rect = canvas.getBoundingClientRect();
const update = (e) => {
const x = ((e.clientX - rect.left) / scale) | 0;
const y = ((e.clientY - rect.top) / scale) | 0;
document.getElementById("mousePos").innerHTML = `(${x}, ${y})`;
};
canvas.addEventListener("mousemove", (e) => {
if (!locked) {
update(e);
}
});
canvas.addEventListener("click", (e) => {
update(e);
locked = !locked;
});
}
{
// Background
context.lineWidth = 6;
context.beginPath();
context.moveTo(
128 / 2 + 120 / 2 * Math.cos(Math.PI / 6),
128 / 2 + 120 / 2 * Math.sin(Math.PI / 6),
);
for (let side = 0; side <= 6; side++) {
context.lineTo(
128 / 2 + 120 / 2 * Math.cos((side * 2 + 1) * Math.PI / 6),
128 / 2 + 120 / 2 * Math.sin((side * 2 + 1) * Math.PI / 6),
);
}
context.closePath();
switch (1) {
case 1:
// On
context.fillStyle = "lightpink";
break;
case 2:
// Off
context.fillStyle = "lightgrey";
break;
}
context.fill();
context.strokeStyle = "black";
context.stroke();
}
{
// Foreground
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "black";
switch (3) {
case 1:
// Nano Adblocker
context.font = "90px Comic Sans MS";
context.fillText("n", 128 / 2 - 1, 128 / 2 - 13);
break;
case 2:
// Nano Defender
context.font = "80px Comic Sans MS";
context.fillText("d", 128 / 2 - 4, 128 / 2 - 5);
break;
case 3:
// Nano Defender Extra
context.font = "125px Comic Sans MS";
context.fillText("+", 128 / 2 + 1, 128 / 2 - 12);
break;
case 4:
// Nano Lab
context.lineJoin = "round";
context.beginPath();
context.moveTo(128 / 2 - 7, 30);
context.lineTo(128 / 2 - 7, 60);
context.lineTo(128 / 2 - 30, 90);
context.lineTo(128 / 2 + 30, 90);
context.lineTo(128 / 2 + 7, 60);
context.lineTo(128 / 2 + 7, 30);
context.stroke();
context.lineJoin = "miter";
context.beginPath();
context.moveTo(128 / 2 - 12, 30);
context.lineTo(128 / 2 - 4, 30);
context.stroke();
context.beginPath();
context.moveTo(128 / 2 + 12, 30);
context.lineTo(128 / 2 + 4, 30);
context.stroke();
break;
}
}
</script>
</body>
</html>