4fingers Posted February 5, 2008 Share Posted February 5, 2008 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. Quote Link to comment Share on other sites More sharing options...
pyrochild Posted February 5, 2008 Share Posted February 5, 2008 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 Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
4fingers Posted February 6, 2008 Author Share Posted February 6, 2008 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 Quote Link to comment Share on other sites More sharing options...
pyrochild Posted February 6, 2008 Share Posted February 6, 2008 What does "Utility.Magnitude(vec)" do?Thanks again It takes the magnitude of a vector. Equivalent to sqrt(vec.X^2 + vec.Y^2) Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.