<!doctype html>
螺旋图案 var canvas=document.getElementById("canvas"); var context=canvas.getContext("2d"); var A,n; btn_onclick=function(){ var width=canvas.width; var height=canvas.height; var X0=width/2; var Y0=height/2; var k=parseInt(document.getElementById("drawType").value); if(k==2) A=Y0*0.25; else A=Y0*0.75; context.save(); context.clearRect(0,0,width,height); context.translate(X0,Y0); context.beginPath(); for(var B=0;B<=6.28;B=B+0.01) draw(B); context.closePath(); context.restore(); } draw=function(B){ var n=10; switch(parseInt(document.getElementById("drawType").value)){ case 1: r=A*Math.sin(n*B); break; case 2: r=A*(Math.sin(n*B)+3*Math.sin(3*n*B)); } x=r*Math.cos(B); y=r*Math.sin(B); context.fillStyle="green"; context.strokeStyle="black"; context.lineTo(-x,-y); context.fill(); context.stroke(); }
蓬莱菊花
令箭荷花