forked from skjApp/HTML5-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCanvasBasic.htm
95 lines (73 loc) · 2.41 KB
/
CanvasBasic.htm
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
<!DOCTYPE HTML>
<html>
<head>
<title>Example - Canvas Basic</title>
</head>
<body>
<canvas id = "canvas1" width = "600" height = "600">
</canvas>
<script type="text/javascript">
var ctx = document.getElementById('canvas1').getContext('2d') ;
// Drawing a simple line
ctx.beginPath() ;
ctx.moveTo(50,50) ; // Starting point of line
ctx.lineTo(100,50) ; // Ending point of line
ctx.closePath() ;
ctx.stroke() ; // Drawing the above coded path
// Stroked Rectangle
ctx.beginPath() ;
ctx.rect(150,50, 100,100) ;
ctx.closePath() ;
ctx.stroke() ;
// Filled Rectangle
ctx.beginPath() ;
ctx.rect(300,50, 100,100) ;
ctx.closePath() ;
ctx.fill() ;
// Stroked Circular Arc
var startAngleinDegrees = 0 ;
var endAngleinDegrees = 120 ;
var startAngleinRadians = (Math.PI/180) * startAngleinDegrees ;
var endAngleinRadians = (Math.PI/180) * endAngleinDegrees ;
ctx.beginPath() ;
ctx.arc(200, 250, 50, startAngleinRadians, endAngleinRadians, false) ;
ctx.stroke() ;
// Stroked Elliptical Arc
/*var startAngleinDegrees = 0 ;
var endAngleinDegrees = 120 ;
var startAngleinRadians = (Math.PI/180) * startAngleinDegrees ;
var endAngleinRadians = (Math.PI/180) * endAngleinDegrees ;
ctx.beginPath() ;
ctx.ellipse(200, 250, 50, 50, 0, startAngleinRadians, endAngleinRadians, false) ;
ctx.closePath() ;
ctx.stroke() ;*/
// Circle
var startAngleinDegrees = 0 ;
var endAngleinDegrees = 360 ;
var startAngleinRadians = (Math.PI/180) * startAngleinDegrees ;
var endAngleinRadians = (Math.PI/180) * endAngleinDegrees ;
ctx.beginPath() ;
ctx.arc(350, 250, 50, startAngleinRadians, endAngleinRadians, false) ;
ctx.stroke() ;
// Ellipse
/*var startAngleinDegrees = 0 ;
var endAngleinDegrees = 360 ;
var startAngleinRadians = (Math.PI/180) * startAngleinDegrees ;
var endAngleinRadians = (Math.PI/180) * endAngleinDegrees ;
ctx.beginPath() ;
ctx.ellipse(200, 250, 50, 50, 0, startAngleinRadians, endAngleinRadians, false) ;
ctx.closePath() ;
ctx.stroke() ;*/
// Quadratic Curve
ctx.beginPath();
ctx.moveTo(450,450);
ctx.quadraticCurveTo(350,450,350,350);
ctx.stroke();
// Bezier Curve
ctx.beginPath();
ctx.moveTo(550,450);
ctx.bezierCurveTo(350,300,400,450,550,350);
ctx.stroke();
</script>
</body>
</html>