-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCanvasIntro.html
68 lines (43 loc) · 1.1 KB
/
CanvasIntro.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>
<head>
<style>
</style>
</head>
<body>
<canvas id="myCanvas" width="500" height="500"></canvas>
<script>
let x = 50;
let y = 100;
let dx = 5;
let dy = 4;
r = 40;
cw = 500;
ch = 500;
let bgColor = 252;
function draw(){
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(x, y, r, 0, 2 * Math.PI, true);
ctx.fillStyle = "#ffffff";
ctx.fillStyle = "#" + bgColor.toString(16);
ctx.fillRect(0,0,500,500);
ctx.fillStyle = "#FFC0CB";
ctx.fill();
if(x < r || x > cw - r){
dx = -dx;
bgColor+= 10;
}
if(y < r || y > ch - r){
dy = -dy;
bgColor+= 10;
}
x+=dx;
y+=dy;
ctx.stroke();
}
setInterval(draw, 30);
</script>
</body>
</html>