如何创建垂直颜色渐变(或除平面水平渐变之外的任何其他角度)

发布于 2024-08-23 11:25:29 字数 1988 浏览 6 评论 0原文

大家好,我第一次尝试在 ActionScript 3 中绘制多色渐变。

所以我从 帮助文档,但我似乎无法获得垂直渐变,无论我使用什么公式或数字进行旋转,它都会卡住在默认水平渐变上:(

我的代码:

您可以在痕迹中看到我尝试过的旋转代码...

package
{
import flash.display.DisplayObject;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.events.*;

public class MyGradient extends MovieClip
{
    private var colorHolder:MovieClip = new MovieClip();
    private var colorGrad:MovieClip = new MovieClip();
    private var fillType:String     = GradientType.LINEAR;
    private var colors:Array        = [0xFF0000, 0x4F8EEC];
    private var alphas:Array        = [1, 1];
    private var ratios:Array        = [0x00, 0xFF];
    private var matr:Matrix         = new Matrix();
    private var spreadMethod:String = SpreadMethod.PAD;


    public function MyGradient():void
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init():void
    {
        colorHolder = new MovieClip();
        colorGrad   = new MovieClip();

        //matr.rotate(30*Math.PI/180);
        //matr.rotate(45);
        //matr.rotate(90);
        //matr.rotate(Math.PI/90);
        matr.rotate(Math.PI/9);
        matr.createGradientBox(200, 200, 0, 0, 1);
        colorGrad.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);        
        colorGrad.graphics.drawRect(0,0,200,200);

        colorHolder.addChild(colorGrad);
        addChild(colorHolder);
        }

    }

}

更新修复 大量涉及

matr.createGradientBox(200, 200, Math.PI/2, 0, 0);

Hey everyone, my first time trying to draw a multi-color gradient in actionscript 3.

So I got this code from the help docs, but I can't seem to get a vertical gradient, whatever formula or number I use for rotate, it stays stuck on the default horizontal gradient :(

My Code:

You can see in the traces the rotation code I tried...

package
{
import flash.display.DisplayObject;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.Shape;
import flash.geom.Matrix;
import flash.events.*;

public class MyGradient extends MovieClip
{
    private var colorHolder:MovieClip = new MovieClip();
    private var colorGrad:MovieClip = new MovieClip();
    private var fillType:String     = GradientType.LINEAR;
    private var colors:Array        = [0xFF0000, 0x4F8EEC];
    private var alphas:Array        = [1, 1];
    private var ratios:Array        = [0x00, 0xFF];
    private var matr:Matrix         = new Matrix();
    private var spreadMethod:String = SpreadMethod.PAD;


    public function MyGradient():void
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init():void
    {
        colorHolder = new MovieClip();
        colorGrad   = new MovieClip();

        //matr.rotate(30*Math.PI/180);
        //matr.rotate(45);
        //matr.rotate(90);
        //matr.rotate(Math.PI/90);
        matr.rotate(Math.PI/9);
        matr.createGradientBox(200, 200, 0, 0, 1);
        colorGrad.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);        
        colorGrad.graphics.drawRect(0,0,200,200);

        colorHolder.addChild(colorGrad);
        addChild(colorHolder);
        }

    }

}

Updated Fix by Heavily involved:

matr.createGradientBox(200, 200, Math.PI/2, 0, 0);

alt text

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

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

发布评论

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

评论(3

记忆之渊 2024-08-30 11:25:29

这行代码将旋转值设置回零:

matr.createGradientBox(200, 200, 0, 0, 1);

如果您查看该函数接受的参数,您会发现第三个参数是旋转。因此,请尝试以下操作:

matr.createGradientBox(200, 200, Math.PI/9, 0, 1);

另外,是否有任何理由将 y 值平移 1 个像素?

希望这有帮助。祝你好运!

This line of code sets the rotation value back to zero:

matr.createGradientBox(200, 200, 0, 0, 1);

If you look at the parameters accepted by the function you'll see that the third parameter is rotation. So, try the following:

matr.createGradientBox(200, 200, Math.PI/9, 0, 1);

Also, is there any reason you are translating the y value by 1 pixel?

Hope this helps. Good luck!

新人笑 2024-08-30 11:25:29

尝试改变这两行的顺序,所以它是:

matr.createGradientBox(200, 200, 0, 0, 1);
matr.rotate((Math.PI/180)*90);

try to change the order of this 2 lines, so it would be:

matr.createGradientBox(200, 200, 0, 0, 1);
matr.rotate((Math.PI/180)*90);
冰葑 2024-08-30 11:25:29

如果你经常画画,你也应该看看 degrafa。

http://www.degrafa.org/

If you're doing a lot of drawing, you should also check out degrafa.

http://www.degrafa.org/

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