var p1x,p1y,p2x,p2y,p3x,p3y; var sourX=0,sourY=-1; window.onload=function() { var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); canvas.width = 800; canvas.height = 600; g=300/30; //var R=g*3; //大圆半径300 //var r=R*(Math.PI*0.135); //小圆半径150 drawBackground(context,200,100); //context.globalCompositeOperation="destination-over"; //setInterval(function(){ // drawBg(context,200,100); //},40); drawStar(context,g*3*(Math.PI*0.135),g*3,g*5,g*6,0); drawStar(context,g*(Math.PI*0.135),g,g*10,g*3,18); drawStar(context,g*(Math.PI*0.135),g,g*12,g*5,36); drawStar(context,g*(Math.PI*0.135),g,g*12,g*8,0); drawStar(context,g*(Math.PI*0.135),g,g*10,g*10,18); } function drawBg(cxt,x,y){ console.log(sum()); cxt.save(); cxt.beginPath(); cxt.moveTo(x,y); cxt.fillStyle="red"; //cxt.bezierCurveTo(x+32, y-26, x+242, y+68, x+300, y+37); cxt.bezierCurveTo(x+32, y-26, x+242, y+68, x+300, y+37); cxt.lineTo(x+300,y+237); cxt.bezierCurveTo(x+162, y+254, x+84, y+138, x, y+174); cxt.lineTo(x,y); cxt.fill(); cxt.closePath(); cxt.restore(); cxt.beginPath(); cxt.moveTo(x,y); cxt.lineTo(x,y+300); cxt.lineWidth=6; cxt.lineCap="round"; cxt.stroke(); cxt.closePath(); } function drawBackground(cxt,x,y){ cxt.save(); cxt.beginPath(); //cxt.translate(200,100); //cxt.bezierCurveTo(x+32, y-26, x+242, y+68, x+300, y+37); //cxt.fillStyle="red"; //cxt.fillRect(200,200,300,200); //cxt.fill(); cxt.moveTo(x,y); cxt.fillStyle="red"; //cxt.bezierCurveTo(x+32, y-26, x+242, y+68, x+300, y+37); cxt.bezierCurveTo(x+112, y-26, x+242, y+68, x+300, y+37); cxt.lineTo(x+300,y+237); cxt.bezierCurveTo(x+162, y+254, x+84, y+138, x, y+174); cxt.lineTo(x,y); cxt.fill(); cxt.closePath(); cxt.restore(); cxt.beginPath(); cxt.moveTo(x,y); cxt.lineTo(x,y+300); cxt.lineWidth=6; cxt.lineCap="round"; cxt.stroke(); cxt.closePath(); } function drawStar(cxt,r,R,x,y,rot){//x,y偏移量,rot旋转角度(顺时针) cxt.save(); cxt.beginPath(); cxt.translate(200,100); for(var i=0;i<5;i++){ cxt.lineTo(Math.cos((18+i*72-rot)/180*Math.PI)*R+x, -Math.sin((18+i*72-rot)/180*Math.PI)*R+y);//大圆半径300 cxt.lineTo(Math.cos((54+i*72-rot)/180*Math.PI)*r+x, -Math.sin((54+i*72-rot)/180*Math.PI)*r+y);//小圆半径150 } cxt.fillStyle="yellow"; cxt.strokeStyle="#aaa"; cxt.lineWidth=0.5; cxt.fill(); cxt.stroke(); cxt.closePath(); cxt.restore(); } function sum(){ sourX++; if(sourX>100){ sourX=-sourX; } return sourX; }