-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo9.html
44 lines (41 loc) · 1.37 KB
/
demo9.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>canvas</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
</head>
<body>
<canvas id="canvas" style="border:1px solid #ccc; margin: 50px auto;display: block;" height="768" width="1024">
如果浏览器不支持canvas的话则会显示这行文字
</canvas>
<script type="text/javascript">
window.onload= function(){
var canvas = document.getElementById("canvas");
var canvastext = canvas.getContext("2d");
// canvastext.lineWidth = 5;
// canvastext.strokeStyle = "#abc";
canvastext.fillStyle = "#abcdef";
var y = 200;
var xs = 0;
// arc() 总共有6个参数 1 2 是圆心坐标 3 是半径 4 5 弧线的开始以及结束点 最后一个是可选参数 默认的是false顺时针,true的话就是逆时针
setInterval(function(){
xs +=0.3;
var c = Math.sin(xs)*5;
// console.log(c)
y = c*5; // 这里只是让y坐标变大一点而已
canvastext.beginPath()
canvastext.clearRect(0, 0, canvas.width, canvas.height); // 清空
canvastext.arc(300,200,y+100,0,2*Math.PI)
canvastext.closePath();
canvastext.fill();
// canvastext.stroke();
},100)
}
</script>
</body>
</html>