五角星收缩探照灯1:
<script type="text/javascript">
var searhLight={x:400,y:400,radius:200,vx:Math.random()*5+10,vy:Math.random()*5+10}
var isIncrease=true;//星星放大
window.onload=function(){
var canvas=document.getElementById('canvas');
canvas.width=800;
canvas.height=800;
var context=canvas.getContext("2d");
setInterval(function(){
draw(context);
updateIncrease(canvas.width,canvas.height);
},40);
}
3赞 · 2采集
慕设计3743538
2016-01-28
圆形探照灯代码3:
function starPath(cxt){
cxt.beginPath();
for (var i = 0; i < 5; i++) {
cxt.lineTo(Math.cos((18+i*72)/180*Math.PI),
-Math.sin((18+i*72)/180*Math.PI));
cxt.lineTo(Math.cos((54+i*72)/180*Math.PI)*0.5,
-Math.sin((54+i*72)/180*Math.PI)*0.5);
};
cxt.closePath();
}
function update(canvasWidth,canvasHeight){
searhLight.x+=searhLight.vx;
searhLight.y+=searhLight.vy;
if(searhLight.x-searhLight.radius <=0){
searhLight.vx=-searhLight.vx;
searhLight.x=searhLight.radius;
}
if(searhLight.x+searhLight.radius>=canvasWidth){
searhLight.vx=-searhLight.vx;
searhLight.x=canvasWidth-searhLight.radius;
}
if(searhLight.y-searhLight.radius<=0){
searhLight.vy=-searhLight.vy;
searhLight.y=searhLight.radius;
}
if(searhLight.y+searhLight.radius>=canvasHeight){
searhLight.vy=-searhLight.vy;
searhLight.y=canvasHeight-searhLight.radius;
}
}