-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmilingFaceDemo.html
More file actions
79 lines (69 loc) · 1.73 KB
/
SmilingFaceDemo.html
File metadata and controls
79 lines (69 loc) · 1.73 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Smiling Face Demo</title>
<style type='text/css'>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id='canvas' width='400' height='300'></canvas>
<script type='text/javascript'>
var ctx;
function drawLine( ctx, x1, y1, x2, y2 ) {
ctx.beginPath();
ctx.moveTo(x1-0.5, y1-0.5);
ctx.lineTo(x2-0.5, y2-0.5);
ctx.closePath();
ctx.stroke();
}
function drawGrid( ctx ) {
var X, Y;
ctx.save();
ctx.fillStyle = "black";
ctx.font = "10px sans-serif";
// labels
for ( X=50; X<ctx.canvas.width; X+=50 )
ctx.fillText( ""+X, X-7, 48 );
for ( Y=100; Y<ctx.canvas.height; Y+=50 )
ctx.fillText( ""+Y, 15, Y+3 );
// lines
ctx.strokeStyle = "#cccccc";
for ( X=0; X<ctx.canvas.width; X+=50 )
drawLine(ctx, X, 0, X, ctx.canvas.height-1); // horizontal
for ( Y=0; Y<ctx.canvas.height; Y+=50 )
drawLine(ctx, 0, Y, ctx.canvas.width-1, Y); // vertical
ctx.restore();
}
function circle( ctx, cx, cy, rad ) {
ctx.beginPath();
ctx.arc(cx, cy, rad, 0, 2*Math.PI, false);
ctx.fill();
}
function draw(ctx) {
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
// draw head
ctx.fillStyle = "yellow";
circle(ctx, 200, 150, 100);
// eyes
ctx.fillStyle = "blue";
circle(ctx, 160, 125, 20);
circle(ctx, 240, 125, 20);
// mouth
ctx.strokeStyle = "red";
ctx.beginPath();
ctx.arc(200,170,50,Math.PI/5,4*Math.PI/5);
ctx.stroke();
// drawGrid(ctx);
}
function main() {
ctx = document.getElementById('canvas').getContext("2d");
draw(ctx);
}
main();
</script>
</body>
</html>