gpt4 book ai didi

canvas - 如何在Dart中使用StageXL绘制虚线圆

转载 作者:行者123 更新时间:2023-12-03 03:46:58 25 4
gpt4 key购买 nike

我正在尝试绘制一个带有虚线边框的圆。我已经试过了:

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行打破了我的代码。任何想法如何解决这个问题?

最佳答案

我想出了这个解决方案:

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);
}
}

关于canvas - 如何在Dart中使用StageXL绘制虚线圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22721870/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com