-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-2-19.html
68 lines (59 loc) · 1.69 KB
/
ex-2-19.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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>호와 원</title>
<link rel="stylesheet" href="css/basic.css">
</head>
<body>
<canvas id="canvas" width="600" height="600">
캔버스를 지원하지 않습니다.
</canvas>
<h1>호와 원</h1>
<h2>arc()</h2>
<p>arc(중심점 좌표x, 중심점 좌표y, 반지름, 시작각, 종료각, 그리는 방향(옵션)) 메소드는 여섯개의 인자를 가진다. 그리는 방향은 생략가능하며 값은 true/false(기본값) 이다. true는 반시계방향, false는 시계방향이다.</p>
<script>
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
// grid
function drawGrid(lineColor){
var gridGap = 50,
numGrid = gridGap / canvas.width,
lineColor;
context.strokeStyle = lineColor;
// horizontal
for ( var posY = gridGap - 0.5, count = 0; posY < canvas.height; posY += gridGap ) {
count++;
context.lineWidth = (count % 2 === 1)
? 0.5
: 1;
context.beginPath();
context.moveTo(0, posY);
context.lineTo(canvas.width, posY);
context.stroke();
}
// vertical
for ( var posX = gridGap - 0.5, count = 0; posX < canvas.width; posX += gridGap ) {
count++;
context.lineWidth = (count % 2 === 1)
? 0.5
: 1;
context.beginPath();
context.moveTo(posX, 0);
context.lineTo(posX, canvas.height);
context.stroke();
}
}
drawGrid('rgba(0,0,0,0.1)');
context.strokeStyle = '#000';
context.lineWidth = 1;
context.beginPath();
context.arc(150,150,100,Math.PI/4,Math.PI,false);
context.stroke();
context.beginPath();
context.moveTo(250,50);
context.arc(400,150,100,Math.PI/4,Math.PI,false);
context.stroke();
</script>
</body>
</html>