0

こんにちは、以下のコードに関する私の問題は、円弧が for ループで指定された 10 ではなく 1 つの形状を作成していることです...

アークからアークに変更する$cd.fillRect(10,20,$x,$y);と、10個の異なる長方形が作成されますが、アークは作成されません...ここで何を誤解していますか?

 
var $canvas = $('#canvas-one')[0],
    $cd;

if ($canvas.getContext) {

$cd = $canvas.getContext('2d');

for (i = 0; i <= 10; i++) {

    $cd.fillStyle = "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")";

    $cd.strokeStyle = "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")";

    var $x = 300 + Math.floor(Math.random() * 101);
    var $y = 300 + Math.floor(Math.random() * 101);
    var $radius = 0.1 + Math.floor(Math.random() * 6);

    $cd.beginPath();

    $cd.arc($x, $y, $radius, 0, Math.PI * 2, true);

}

$cd.stroke();
$cd.fill();

//$canvas.width = $canvas.height;

}

4

2 に答える 2

1

ストロークと塗りつぶしはループ内にある必要があります

于 2011-02-11T08:36:39.337 に答える