1

HTML5 の canvas 要素を使用して一連の円を作成しています。while ループを使用して、円のサイズをインクリメントしています。それらを 3 ずつインクリメントしようとしていますが、正しい構文がわかりません。

    var cirSize = 2;

    while (cirSize < 400)
      {
        ctx.beginPath();
        ctx.strokeStyle="#000000"; 
        ctx.arc(480,480,cirSize++,0,Math.PI*2,true);
        ctx.stroke();
        alert(cirSize)
      }

ありがとう

4

1 に答える 1

2

cirSize++1ずつ増加するので、++cirSize。しかし、違いがあります。前者は、最初にの値を返し、次に増分します。後者は最初に増分し、次にの値を返しますがcirSizecirSize

var cirSize = 2;

while (cirSize < 400)
  {
    ctx.beginPath();
    ctx.strokeStyle="#000000"; 
    ctx.arc(480,480,cirSize,0,Math.PI*2,true);
    ctx.stroke();
    cirSize += 3; // here's the change.
    alert(cirSize)
  }
于 2012-06-06T14:35:12.610 に答える