composer @Ta | |
2015-07-20 21:28 |
<canvas id="mc" width="420" height="280" style="border:1px solid black"></canvas>
<script type="text/javascript">
function createFlower(context,n,dx,dy,size,length){
context.beginPath();
context.moveTo(dx,dy+size);
var dig = 2*Math.PI/n;
for(var i=1;i<n+1;i++){
var ctrlX = Math.sin((i-0.5)*dig)*length+dx;
var ctrlY = Math.cos((i-0.5)*dig)*length+dy;
var x = Math.sin(i*dig)*size+dx;
var y = Math.cos(i*dig)*size+dy;
context.quadraticCurveTo(ctrlX,ctrlY,x,y);
}
context.closePath();
}
snowPos = [
,,
,,
,,
,,
,,
,,
,];
function fall(context){
context.fillStyle = "#000";
context.fillRect(0,0,420,280);
context.fillStyle = "#fff";
for(var i=0,len=snowPos.length;i<len;i++){
context.save();
context.translate(snowPos<i>.x,snowPos<i>.y);
context.rotate((Math.random()*6-3)*Math.PI/10);
snowPos<i>.y += Math.random()*18;
if(snowPos<i>.y>280){
snowPos<i>.y=4;
}
createFlower(context,6,0,0,snowPos<i>.z,8);
context.fill();
context.restore();
}
}
var canvas = document.getElementById("mc");
var ctx = canvas.getContext("2d");
setInterval("fall(ctx);",200);
</script>
阅:2758 | 发表于2015-07-20 21:28 |
心灵鸡汤:
      
®2019-2024 all power by Zlproject3.7
川公网安备 51192202000151号
蜀ICP备2021014921号-2
首页 #top
天合之作 曲在人意