2014-03-28 37 views
1

我正在嘗試繪製帶有虛線邊框的圓。我已經試過這樣:如何在Dart中使用StageXL繪製虛線圓

Shape shape = new Shape() 
..graphics.beginPath() 
      ..graphics.circle(50 , 50, 50) 
      ..graphics.closePath() 
      ..graphics.strokePattern(new GraphicsPattern.repeat(new BitmapData.fromImageElement(new HTML.ImageElement(src: "img/dash.png")))) 
      ..addTo(stage); 
    } 

但圈沒有得到顯示。看來,strokePattern行破壞我的代碼。任何想法如何解決這個問題?

回答

1

我想出了這個解決方案:

void _addDottedCircle(double x, double y, int radius) { 
    List<double> xCoords = new List<double>(); 
    List<double> yCoords = new List<double>(); 

    for (int i = 0; i < radius; i++) { 
     xCoords.add(radius * cos(2 * PI * i/radius) + x); 
     yCoords.add(radius * sin(2 * PI * i/radius) + y); 
    } 

    for (int i = 0; i < radius; i++) { 
     new Shape() 
      ..graphics.beginPath() 
      ..graphics.circle(xCoords[i], yCoords[i], 1) 
      ..graphics.closePath() 
      ..graphics.fillColor(lightgreen) 
      ..addTo(stage); 
    } 
}