如何在 Actionscript 3.0 中捕捉线条样式?

发布于 2024-10-31 05:59:49 字数 159 浏览 1 评论 0原文

海,我是动作脚本的新手。

我正在尝试在 ActionScript 3 中制作一个画笔工具,孩子们可以使用画笔在圆圈内绘制颜色。我已经使用线条样式实现了这一点。现在我希望画笔在孩子即将完成时(比如当他们完成绘画的 95% 时)捕捉颜色。我怎么知道孩子在圆圈上画了多少?

谢谢

Hai, i am a newbie to actionscript.

i am trying to make a brush tool in actionscript 3, where kids can paint colors inside a circle using the brush. i have achieved this using linestyle. Now i want the brush to snap the color when the kid is about to complete(say when they are 95% to complete the painting). How do i know how much the kid has painted on the circle?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抹茶夏天i‖ 2024-11-07 05:59:49

我怎么知道孩子有多少钱
画在圆圈上?

您可以:

  • 制作圆形和其他形状的精灵以获得单独的容器
  • 将它们渲染为位图并计算其中的非透明像素数(您应该知道哪个数字对应于100%),
  • 因为计算像素是繁重的操作(可能需要数百次)毫秒,取决于形状大小),您不想在每一帧上运行它。我建议在孩子完成下一次划水后立即在 MOUSE_UP 上执行此操作。

如何计算像素:

function countPixels(shape:DisplayObject):int
{
    var bd:BitmapData = new BitmapData(shape.width, shape.height);
    bd.draw(shape);

    //here you get sequence of ARGB-packed colors in vector
    var pixels:Vector.<uint> = bd.getVector(bd.rect);

    //AFAIK, fastest method to traverse vector is 'for' loop
    var pixel:uint;
    var filledCount:int = 0;
    for (var i:int = pixels.length - 1; i >= 0; i--)
    {
        pixel = pixels[i];
        //pixel is 32-bit ARGB color value, test upper 8 bits (alpha):
        if ((pixel >> 24) > 0) filledCount++;
    }
    return filledCount;
}

在填充形状上运行此命令以获得要比较的总像素数。
当像素数达到95%后,您可以清除孩子的绘图并显示填充的形状。

How do i know how much the kid has
painted on the circle?

You can:

  • make your circles and other shapes Sprites to get separate container
  • render them into bitmap and count number of non-transparent pixels in it (you should know what number corresponds to 100%)
  • since counting pixels is heavy operation (can take hundreds of milliseconds, depending of shape size), you don't want to run it on every frame. I suggest to do it on MOUSE_UP, right after kid finishes next stroke.

How to count pixels:

function countPixels(shape:DisplayObject):int
{
    var bd:BitmapData = new BitmapData(shape.width, shape.height);
    bd.draw(shape);

    //here you get sequence of ARGB-packed colors in vector
    var pixels:Vector.<uint> = bd.getVector(bd.rect);

    //AFAIK, fastest method to traverse vector is 'for' loop
    var pixel:uint;
    var filledCount:int = 0;
    for (var i:int = pixels.length - 1; i >= 0; i--)
    {
        pixel = pixels[i];
        //pixel is 32-bit ARGB color value, test upper 8 bits (alpha):
        if ((pixel >> 24) > 0) filledCount++;
    }
    return filledCount;
}

Run this on filled shape to get total pixel count to compare with.
After pixelCount reaches 95%, you can clear kid's drawing and show filled shape.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文