利用canvas画星星的代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>画星星</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<script type="text/javascript">
window.onload=function(){
var canvas=document.getElementById('canvas');
canvas.width=600;
canvas.height=600;
canvas.style.border="1px solid red";
if (canvas.getContext("2d")) {
var context=canvas.getContext("2d");

drawStar(context,200,100,300,300);

}else{
alert("你的浏览器版本过低,不支持canvas");
}

}

function drawStar(context,rx,ry,x,y){
context.beginPath();

context.strokeStyle="red";
context.lineWidth="5";
for (var i=0;i<5;i++) {
context.lineTo(Math.cos((18+i*72)/180*Math.PI)*rx+x,-Math.sin((18+i*72)/180*Math.PI)*rx+x);
context.lineTo(Math.cos((54+i*72)/180*Math.PI)*ry+y,-Math.sin((54+i*72)/180*Math.PI)*100+y);
};
context.closePath();
context.stroke();

}
</script>
</head>
<body>
<canvas ></canvas>
</body>
</html>

相关文章:

  • 2022-12-23
  • 2021-10-23
  • 2021-08-09
  • 2021-07-31
  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
猜你喜欢
  • 2022-12-23
  • 2021-04-15
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案