用html5的canvas画布绘制贝塞尔曲线完整代码

建站知识 2021-07-02 23:00www.168986.cn长沙网站建设
查看效果http://keleyi./keleyi/phtml/html5/7.htm
完整代码

复制代码
代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://.w3./1999/xhtml">
<head>
<title>用html5的canvas画布绘制贝塞尔曲线</title>
</head>
<body>
<div>
<a href="http://keleyi./a/bjac/j77m9131.htm" target="_blank">原文</a></div>
<canvas id="keleyi_" height="300" width="400"></canvas>
<script type="text/javascript">
function draw(id)
{
var canvas=document.getElementById(id);
if(canvas==null)
return false;
var context=canvas.getContext('2d');
context.fillStyle="#eeeeff";
context.fillRect(0,0,400,300);
var n=0;
var dx=150;
var dy=150;
var s=100;
context.beginPath();
context.globalCompositeOperation='and';
context.fillStyle='rgb(100,255,100)';
context.strokeStyle='rgb(0,0,100)';
var x=Math.sin(0);
var y=Math.cos(0);
var dig=Math.PI/1511;
for(var i=0;i<30;i++)
{
var x=Math.sin(idig);
var y=Math.cos(idig);
context.bezierCurveTo(dx+xs,dy+ys-100,dx+xs+100,dy+ys,dx+xs,dy+ys);
}
context.closePath();
context.fill();
context.stroke();
}
draw("keleyi_");
</script>
</body>
</html>

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by