-
Notifications
You must be signed in to change notification settings - Fork 6
/
line.html
65 lines (57 loc) · 1.62 KB
/
line.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Sample - ICS MEDIA</title>
<style>
body {
margin: 0;
height: 0;
overflow: hidden;
}
canvas {
width: 100vw;
height: 100vh;
background: black;
}
</style>
</head>
<body>
<canvas></canvas>
<script>
let stageW = 0; // 画面の幅
let stageH = 0; // 画面の高さ
// canvas要素の参照を取得
const canvas = document.querySelector("canvas");
// 2Dの描画命令群を取得
const context = canvas.getContext("2d");
tick();
resize();
window.addEventListener("resize", resize);
/** アニメーションフレームのタイミングです。 */
function tick() {
requestAnimationFrame(tick);
draw();
}
/** 描画します。 */
function draw() {
// 画面をリセット
context.clearRect(0, 0, stageW, stageH);
context.lineWidth = 10; // 線の太さ
context.beginPath(); // 線の開始
context.strokeStyle = "white"; // 線の色
context.moveTo(0, stageH / 2); // 開始点
context.lineTo(stageW, stageH / 2); // 終了点
context.stroke(); // 線を描く
}
/** リサイズ時のイベントです。 */
function resize() {
stageW = innerWidth * devicePixelRatio;
stageH = innerHeight * devicePixelRatio;
canvas.width = stageW;
canvas.height = stageH;
}
</script>
</body>
</html>