2014-03-28 35 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); 
    } 
}