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

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

最佳答案

我想出了这个解决方案:

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/

相关文章:

colors - StageXL 和颜色值

Dart StageXL 鼠标单击时 Sprite 颜色变化

javascript - 缩放 Canvas 后如何在 Canvas 中以原始大小保存图像

logging - 创建一个中间件 Controller 以处理Dart中对Aqueduct的所有请求

firebase - 如何在flutter中使用firebase电话身份验证中的forceResendingToken来重新发送otp

dart - flutter 并将数据保存到本地存储

dart - 我如何在我的应用程序中使用静态成员,这取决于我的库的依赖性

canvas - 在 Konvajs 中更改宽度和大小而不是 scaleX 和 scaleY

Android Canvas 路径实时性能

c# - 保持 Canvas 元素相对于背景图像定位