BoltBait Posted April 27, 2012 Share Posted April 27, 2012 User bugman was asking about a different type of gradient... so I coded it up! I also remember someone asking about gradients that had dithering built in. So, I included that. Also, since I really love HSV gradients, I included that too! GradientTest.zip Enjoy. Obviously it still needs a lot of polish to finish it. But, hopefully some people will find it useful even in its unfinished state. Here is the CodeLab script: // Author: BoltBait // Submenu: Render // Name: Gradients // Title: BoltBait's Gradient Test // URL: http://www.BoltBait.com/pdn #region UICode byte Amount1 = 0; // Method|RGB|HSV byte Amount2 = 0; // Direction|Vertical|Horizontal ColorBgra Amount3 = ColorBgra.FromBgr(0,0,0); // From ColorBgra Amount4 = ColorBgra.FromBgr(255,255,255); // To bool Amount5 = true; // [0,1] Dither #endregion private byte Clamp2Byte(float fValue) { if (fValue<0) return 0; if (fValue>255) return 255; return (byte)fValue; } private byte Clamp2100(float fValue) { if (fValue<0) return 0; if (fValue>100) return 100; return (byte)fValue; } public int Clamp2360(float MyAngle) { // Makes sure that 0.0 <= MyAngle < 360.0 if (MyAngle >= 360.0) { MyAngle -= (float)(Math.Floor((double)MyAngle / 360.0) * 360.0); } if (MyAngle < 0.0) { MyAngle += (float)360.0; } return (int)MyAngle; } Random R = new Random(); void Render(Surface dst, Surface src, Rectangle rect) { Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); float v1,v2,v3; float f1,f2,f3; float t1,t2,t3; float d1,d2,d3; float maxd, d, a; HsvColor hsv; // Calculate the maximum size of the fade if (Amount2==0) { maxd = selection.Bottom - selection.Top; } else { maxd = selection.Right - selection.Left; } // Select the starting and ending color of the fade if (Amount1==0) // RGB { f1 = Amount3.R; f2 = Amount3.G; f3 = Amount3.B; t1 = Amount4.R; t2 = Amount4.G; t3 = Amount4.B; } else // HSV { hsv = HsvColor.FromColor(Amount3.ToColor()); f1 = hsv.Hue; f2 = hsv.Saturation; f3 = hsv.Value; hsv = HsvColor.FromColor(Amount4.ToColor()); t1 = hsv.Hue; t2 = hsv.Saturation; t3 = hsv.Value; // is the shortest path crossing the 0 barrier? if (Math.Abs(f1 - t1) > (360-Math.Max(f1,t1)+Math.Min(f1,t1))) { // wrap ending color if (f1 > t1) { t1 += 360; } else { t1 = -360 + t1; } } } ColorBgra CurrentPixel; for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { CurrentPixel = src[x,y]; // dithering? int adj = 0; if (Amount5) { adj = R.Next(-1,2); } // calculate current pixel distance if (Amount2==0) // Vertical { d = (180 * (((y+adj)+adj) - selection.Top)) / maxd; } else // Horizontal { d = (180 * (((x+adj)+adj) - selection.Left)) / maxd; } // calculate percentage of adjustment a = (float)(Math.Cos(d * (Math.PI/180)) + 1) / 2; // calculate adjustment from first color d1 = (t1 - f1) * a; d2 = (t2 - f2) * a; d3 = (t3 - f3) * a; // calculate current color v1 = f1 + d1; v2 = f2 + d2; v3 = f3 + d3; // recombine into a color if (Amount1 == 0) { CurrentPixel.R = Clamp2Byte(v1); CurrentPixel.G = Clamp2Byte(v2); CurrentPixel.B = Clamp2Byte(v3); } else { hsv = new HsvColor(Clamp2360(v1),Clamp2100(v2),(int)v3); CurrentPixel = ColorBgra.FromColor(hsv.ToColor()); } // make opaque CurrentPixel.A = (byte)255; // show it dst[x,y] = CurrentPixel; } } } I think the from and to colors may be switched. Sorry about that. 1 Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Red ochre Posted April 27, 2012 Share Posted April 27, 2012 Ha Ha - beat me to it! I was revamping one I started ages ago, but didn't finish. It's got a working angle slider and an ellipse/squirkle option ! - but still work in progress . Oh well! ( I can PM you my source if you're interested in incorperating the angle in yours) Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted April 27, 2012 Share Posted April 27, 2012 @Boltbait: Why are you still inisisting on rolling your own Clamp2Byte function? Rick hasn't moved the current one for ages Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
BoltBait Posted April 27, 2012 Author Share Posted April 27, 2012 Hey, I don't have to learn a lesson more than once. Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Lance McKnight Posted May 8, 2012 Share Posted May 8, 2012 Bolt, how is this different from the gradient plug-in from KrisVDM's pack? Quote Officially retired from this forum. Have a nice day. Link to comment Share on other sites More sharing options...
BoltBait Posted May 8, 2012 Author Share Posted May 8, 2012 Lance, I have no idea. I've never used his pack. I would say that it is most like the gradient plugin I wrote first. (My first plugin.) Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Tanel Posted May 14, 2012 Share Posted May 14, 2012 Dithering disappears at some point when sliding the nub around in (either) color wheel. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted May 14, 2012 Author Share Posted May 14, 2012 That might have something to do with the random number function. Perhaps if it was built as a regular effect instead of a CodeLab effect the random function could be moved out of the render function and somewhere else. Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
AhmedElyamani Posted August 31, 2012 Share Posted August 31, 2012 it's nice but it's only dithering the top 26 pixels Quote Link to comment Share on other sites More sharing options...
RFX Posted October 8, 2012 Share Posted October 8, 2012 I also want to create a fade plug-in with the same effect bugman mentioned but with a few other options so I posted my idea here Plug-In Advice - How do I create a "fade plug-in". I was referred to the gradient plug in and am looking forward to checking it out! Thanks BoltBait! Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted October 8, 2012 Share Posted October 8, 2012 Not quite. You were referred to the Gradient Tool This tool does the functions you were requesting - no plugin required. 1 Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
RFX Posted October 15, 2012 Share Posted October 15, 2012 lol thanks Ego Eram Reputo! I should lay off the blunts a bit till I get used to where everything is. xD Quote 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.