forked from skjApp/HTML5-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCanvasColorStyles.htm
52 lines (37 loc) · 1.16 KB
/
CanvasColorStyles.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
<!DOCTYPE HTML>
<html>
<head>
<title>Example - Canvas Color Styles</title>
</head>
<body>
<canvas id = "canvas1" width = "600" height = "600">
</canvas>
<script type="text/javascript">
var ctx = document.getElementById('canvas1').getContext('2d') ;
// Setting Stroke Color by name
ctx.strokeStyle = "blue" ;
ctx.strokeRect(35,35,60,60) ;
// Setting Stroke Color by rgb
ctx.strokeStyle = 'rgb(255,0,0)' ;
ctx.strokeRect(135,35,60,60) ;
// Setting Stroke Color by rgba
ctx.strokeStyle = 'rgba(255,0,0,0.5)' ;
ctx.strokeRect(235,35,60,60) ;
// Setting Stroke Color by rgb as hexvalue
ctx.strokeStyle = '#00ff00' ;
ctx.strokeRect(335,35,60,60) ;
// Setting Fill Color by name
ctx.fillStyle = "blue" ;
ctx.fillRect(35,135,60,60) ;
// Setting Fill Color by rgb
ctx.fillStyle = 'rgb(255,0,0)' ;
ctx.fillRect(135,135,60,60) ;
// Setting Fill Color by rgba
ctx.fillStyle = 'rgba(255,0,0,0.5)' ;
ctx.fillRect(235,135,60,60) ;
// Setting Fill Color by rgb as hexvalue
ctx.fillStyle = '#00ff00' ;
ctx.fillRect(335,135,60,60) ;
</script>
</body>
</html>