Jump to content

Help understanding the Conical and Diamond gradients


4fingers
 Share

Recommended Posts

Hi,

I was just wondering how the Conical and Diamond gradients were achieved.

So far I have only been able to get a linear like gradient using something like this:

gradient = sin(pos.x * Pi)

I am just interested in the algorithm or pseudo code. I tried looking at the source but had no idea where to look.

Any help would be great.

Link to comment
Share on other sites

I tried looking at the source but had no idea where to look.

Any help would be great.

Relevant files:

\pdn_src_3_20\src\tools\GradientTool.cs

\pdn_src_3_20\src\Core\GradientRenderer.cs

\pdn_src_3_20\src\Core\GradientRenderers.cs

Also, http://en.wikipedia.org/wiki/Image_gradient

xZYt6wl.png

ambigram signature by Kemaru

[i write plugins and stuff]

If you like a post, upvote it!

Link to comment
Share on other sites

Thanks for the tip I think I managed to find the code I was looking for:

public sealed class LinearDiamond
           : LinearStraight
       {
           public override float ComputeUnboundedLerp(int x, int y)
           {
               float dx = x - StartPoint.X;
               float dy = y - StartPoint.Y;

               float lerp1 = (dx * this.dtdx) + (dy * this.dtdy);
               float lerp2 = (dx * this.dtdy) - (dy * this.dtdx);

               float absLerp1 = Math.Abs(lerp1);
               float absLerp2 = Math.Abs(lerp2);

               return absLerp1 + absLerp2;
           }

           public override float BoundLerp(float t)
           {
               return Utility.Clamp(t, 0, 1);
           }

           public LinearDiamond(bool alphaOnly, BinaryPixelOp normalBlendOp)
               : base(alphaOnly, normalBlendOp)
           {
           }
       }

I was just wondering what was held in the variables "this.dtdx" and "this.dtdy". Although I can see the code I am not quite sure what it is doing:

protected float dtdx;
           protected float dtdy;

           public override void BeforeRender()
           {
               PointF vec = new PointF(EndPoint.X - StartPoint.X, EndPoint.Y - StartPoint.Y);
               float mag = Utility.Magnitude(vec);

               if (EndPoint.X == StartPoint.X)
               {
                   this.dtdx = 0;
               }
               else
               {
                   this.dtdx = vec.X / (mag * mag);
               }

               if (EndPoint.Y == StartPoint.Y)
               {
                   this.dtdy = 0;
               }
               else
               {
                   this.dtdy = vec.Y / (mag * mag);
               }

               base.BeforeRender();
           }

What does "Utility.Magnitude(vec)" do?

Why do you do "this.dtdx = vec.X / (mag * mag)" when both end and start points are the same?

Thanks again

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...