Illnab1024 Posted May 29, 2012 Share Posted May 29, 2012 Quick little codelab plugin: Color Star. It creates a specified number of colors equidistant in hue, similar to placing a regular polygon star on the color wheel and picking colors at the points. >> ColorStar.zip << Source: Hidden Content: Source #region UICode int Amount1=7; //[1,100]Number double Amount2=2.0; //[0,100]Angle double Amount3=10; //[0,50]Saturation Deviation double Amount4=10; //[0,50]Value Deviation #endregion void Render(Surface dst, Surface src, Rectangle rect) { Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); int width = selection.Right - selection.Left; int numCols = Amount1; for (int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { dst[x,y] = colors[(int)Math.Floor(numCols * (double)x/width)]; } } } List<ColorBgra> _colors = new List<ColorBgra>(); internal struct Params { int a1; double a2; double a3; double a4; public Params(int p1, double p2, double p3, double p4) { a1 = p1; a2 = p2; a3 = p3; a4 = p4; } public override bool Equals(object obj) { Params param = (Params)obj; return param.a1 == a1 && param.a2 == a2 && param.a3 == a3 && param.a4 == a4; } } Params lastParams; List<ColorBgra> colors { get { int numCols = Amount1; Params newParams = new Params(Amount1, Amount2, Amount3, Amount4); if (_colors.Count != numCols || !lastParams.Equals(newParams)) { lastParams = newParams; double devSat = Amount3; double devVal = Amount4; double q = Amount2; _colors = new List<ColorBgra>(numCols); HsvColor primary = HsvColor.FromColor(EnvironmentParameters.PrimaryColor); double jump = q * 360 / numCols; double h = primary.Hue; double s = primary.Saturation; double v = primary.Value; Random r = new Random(); for (int i = 0; i < numCols; i++) { _colors.Add(ColorBgra.FromColor(new HsvColor( (int)((h += jump))%361, clamp((int)((s + devSat * r.NextDouble())), 100), clamp((int)((v + devVal * r.NextDouble())), 100) ).ToColor())); } } return _colors; } } int clamp(int n, int max) { if (n >= max) return max; if (n <= 0) return 0; return n; } Quote ~~ Link to comment Share on other sites More sharing options...
Red ochre Posted May 30, 2012 Share Posted May 30, 2012 Many thanks, Thanks for publishing the codelab code too, and your clipboard code in the tutorials is really useful as well. Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings 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.