问答详情
源自:2-3 绘制弧和圆

谁能解答一下这段代码,三角形堆叠成的一个花朵

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>叠放三角形</title>

<script type="text/javascript">

window.onload = function draw()

{

// body...

var canvas = document.getElementById("canvas");

var ctx = canvas.getContext("2d");

ctx.fillStyle = "red";

ctx.fillRect(0,0,400,300);


var n=0,dx=170,dy=150,s=140;

ctx.beginPath();

ctx.fillStyle="blue";

ctx.strokeStyle="yellow";

var x=Math.sin(0);

var y=Math.cos(0);

var dig=Math.PI*15/11;

for (var i = 0; i < 30; i++) {

var x=Math.sin(i*dig);

var y=Math.cos(i*dig);

ctx.lineTo(dx+x*s,dy+y*s);

}

ctx.closePath();

ctx.fill();

ctx.stroke();


}

</script>

</head>

<body>

<canvas id="canvas" width="400" height="300"></canvas>

</body>

</html>


提问者:qq_莫念默念_0 2017-03-21 20:48

个回答

  • H_action
    2017-03-24 11:13:53

    同问。