Spaces:
Running
Running
add center white circle to the canvas
Browse files- index.html +33 -78
- plasma-arc-01.jpg +0 -0
- style.css +21 -14
index.html
CHANGED
@@ -3,98 +3,53 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>
|
7 |
-
<style>
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
<script
|
12 |
-
const
|
13 |
-
|
14 |
-
fpsFontSize: '14px', versionFontSize: '10px', canvasId: 'plasma-arc-canvas', padding: 10
|
15 |
-
};
|
16 |
-
|
17 |
-
const state = {
|
18 |
-
fpsX: config.padding * 7, fpsY: config.padding, nameX: null, nameY: null, versionY: null, lastFrameTime: 0, fps: 0, smoothFPS: 0
|
19 |
-
};
|
20 |
-
|
21 |
-
function lerp(start, end, amount) {
|
22 |
-
return start + (end - start) * amount;
|
23 |
-
}
|
24 |
-
|
25 |
-
function createCanvas() {
|
26 |
-
const canvas = document.createElement('canvas');
|
27 |
-
canvas.id = config.canvasId;
|
28 |
-
document.body.appendChild(canvas);
|
29 |
-
return canvas;
|
30 |
-
}
|
31 |
|
32 |
-
|
33 |
-
resizeCanvas(canvas);
|
34 |
-
fillCanvasWithColor(canvas, context);
|
35 |
-
updateTextPositions(canvas);
|
36 |
-
}
|
37 |
|
38 |
-
function
|
39 |
canvas.width = window.innerWidth;
|
40 |
canvas.height = window.innerHeight;
|
41 |
-
|
42 |
-
|
43 |
-
function fillCanvasWithColor(canvas, context) {
|
44 |
-
context.fillStyle = config.backgroundColor;
|
45 |
context.fillRect(0, 0, canvas.width, canvas.height);
|
46 |
}
|
47 |
|
48 |
-
function
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
}
|
53 |
|
54 |
-
|
55 |
-
context.
|
56 |
-
context.
|
57 |
-
context.
|
58 |
-
context.
|
59 |
-
context.fillText(text, x, y);
|
60 |
}
|
61 |
|
62 |
-
function
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
|
66 |
-
function
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
const canvas = createCanvas();
|
71 |
-
const context = canvas.getContext('2d');
|
72 |
-
initializeCanvas(canvas, context);
|
73 |
-
|
74 |
-
function tick(currentTime) {
|
75 |
-
const deltaTime = (currentTime - state.lastFrameTime) / 1000;
|
76 |
-
state.lastFrameTime = currentTime;
|
77 |
-
const currentFPS = 1 / deltaTime;
|
78 |
-
|
79 |
-
state.smoothFPS = lerp(state.smoothFPS, currentFPS, 0.1);
|
80 |
-
|
81 |
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
82 |
-
fillCanvasWithColor(canvas, context);
|
83 |
-
|
84 |
-
drawText(context, `${formatFPS(state.smoothFPS)} fps`, state.fpsX, state.fpsY, config.fpsFontSize, 'right', 'top');
|
85 |
-
drawText(context, config.name, state.nameX, state.nameY, config.fontSize, 'right', 'bottom');
|
86 |
-
drawText(context, config.version, state.nameX, state.versionY, config.versionFontSize, 'right', 'bottom');
|
87 |
-
|
88 |
-
requestAnimationFrame(tick);
|
89 |
-
}
|
90 |
-
|
91 |
-
window.addEventListener('resize', () => initializeCanvas(canvas, context));
|
92 |
-
requestAnimationFrame(tick);
|
93 |
}
|
94 |
|
95 |
-
|
|
|
|
|
96 |
</script>
|
97 |
-
</head>
|
98 |
-
<body>
|
99 |
</body>
|
100 |
</html>
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Minimalist White Circle</title>
|
7 |
+
<link rel="stylesheet" href="style.css">
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<canvas id="canvas"></canvas>
|
11 |
+
<script>
|
12 |
+
const canvas = document.getElementById('canvas');
|
13 |
+
const context = canvas.getContext('2d');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
const versionText = 'v1.0.0';
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
function initializeCanvas() {
|
18 |
canvas.width = window.innerWidth;
|
19 |
canvas.height = window.innerHeight;
|
20 |
+
context.fillStyle = 'black';
|
|
|
|
|
|
|
21 |
context.fillRect(0, 0, canvas.width, canvas.height);
|
22 |
}
|
23 |
|
24 |
+
function drawWhiteCircle() {
|
25 |
+
const centerX = canvas.width / 2;
|
26 |
+
const centerY = canvas.height / 2;
|
27 |
+
const radius = Math.min(canvas.width, canvas.height) * 0.0125; // 1.25% of the smaller dimension
|
|
|
28 |
|
29 |
+
context.beginPath();
|
30 |
+
context.arc(centerX, centerY, radius, 0, 2 * Math.PI);
|
31 |
+
context.strokeStyle = 'white';
|
32 |
+
context.lineWidth = 0.25 * parseFloat(getComputedStyle(document.documentElement).fontSize); // 0.25em stroke
|
33 |
+
context.stroke();
|
|
|
34 |
}
|
35 |
|
36 |
+
function drawVersionText() {
|
37 |
+
context.font = '1em Arial';
|
38 |
+
context.fillStyle = 'white';
|
39 |
+
context.textAlign = 'right';
|
40 |
+
context.textBaseline = 'bottom';
|
41 |
+
context.fillText(versionText, canvas.width - 10, canvas.height - 10);
|
42 |
}
|
43 |
|
44 |
+
function draw() {
|
45 |
+
initializeCanvas();
|
46 |
+
drawWhiteCircle();
|
47 |
+
drawVersionText();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
}
|
49 |
|
50 |
+
draw();
|
51 |
+
|
52 |
+
window.addEventListener('resize', draw);
|
53 |
</script>
|
|
|
|
|
54 |
</body>
|
55 |
</html>
|
plasma-arc-01.jpg
ADDED
style.css
CHANGED
@@ -1,28 +1,35 @@
|
|
1 |
body {
|
2 |
-
|
3 |
-
|
|
|
4 |
}
|
5 |
|
6 |
h1 {
|
7 |
-
|
8 |
-
|
9 |
}
|
10 |
|
11 |
p {
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
}
|
17 |
|
18 |
.card {
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
}
|
25 |
|
26 |
.card p:last-child {
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
}
|
|
|
1 |
body {
|
2 |
+
padding: 0;
|
3 |
+
margin: 0;
|
4 |
+
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
5 |
}
|
6 |
|
7 |
h1 {
|
8 |
+
font-size: 10em;
|
9 |
+
margin-top: 0;
|
10 |
}
|
11 |
|
12 |
p {
|
13 |
+
color: rgb(107, 114, 128);
|
14 |
+
font-size: 1em;
|
15 |
+
margin-bottom: 10px;
|
16 |
+
margin-top: 5px;
|
17 |
}
|
18 |
|
19 |
.card {
|
20 |
+
max-width: 620px;
|
21 |
+
margin: 0 auto;
|
22 |
+
padding: 16px;
|
23 |
+
border: 1px solid lightgray;
|
24 |
+
border-radius: 16px;
|
25 |
}
|
26 |
|
27 |
.card p:last-child {
|
28 |
+
margin-bottom: 0;
|
29 |
+
}
|
30 |
+
|
31 |
+
canvas {
|
32 |
+
display: block;
|
33 |
+
margin: 0 auto;
|
34 |
+
background-color: black;
|
35 |
}
|