日期:2014-05-16 浏览次数:20421 次
<!DOCTYPE html>
<html>
<head>
<meta charset="gb3212">
<style type="text/css">
body{margin:0;}
canvas{margin: 0px;}
</style>
</head>
<body >
<style>
#canvas{
position: absolute;
left:50px;
top:50px;
}
#div1{
position: absolute;
background-color:blue;
width:5px;
height:5px;
}
</style>
<div id="div1"></div>
<canvas id="canvas" width="200" height="200" style="border: 1px solid #ccc;"></canvas>
<button id="bnt" onclick="beginDraw()">开始画贝塞尔曲线</button>
<button id="bnt" onclick="play()">沿着贝赛尔曲线运动</button>
先点"开始画贝塞尔曲线",在方框点三次不同坐标,生成曲线后,点第二按钮
<script>
var canvas=document.getElementById('canvas');
var context=canvas.getContext('2d');
var ctx=context;
var bnt=document.getElementById('bnt');
var isDraw=0,drawIndex=0,drawPs=[];
function beginDraw(){
ctx.restore();
ctx.clearRect(0,0,200,200);
isDraw=1;
drawIndex=0;
drawPs=[];
bnt.disabled=true;