Пример #1
0
 public static double GetBrightness(this GsColor c)
 {
     return(Math.Sqrt(
                c.R * c.R * .241 +
                c.G * c.G * .691 +
                c.B * c.B * .068));
 }
Пример #2
0
        public static GsColor LightOrDark(this GsColor color)
        {
            double bright = color.GetBrightness();

            if (bright < 130)
            {
                return(color.Lighten());
            }
            else
            {
                return(color.Darken());
            }
        }
Пример #3
0
        public static GsColor Interpolate(GsColor c1, GsColor c2, float amount, Func <float, float, float, float> op)
        {
            // start colours as lerp-able floats
            float sr = c1.R, sg = c1.G, sb = c1.B;

            // end colours as lerp-able floats
            float er = c2.R, eg = c2.G, eb = c2.B;

            // lerp the colours to get the difference
            byte r = (byte)op(sr, er, amount),
                 g = (byte)op(sg, eg, amount),
                 b = (byte)op(sb, eb, amount);

            // return the new colour
            return(new GsColor(r, g, b));
        }
Пример #4
0
 public static GsColor SmoothStep(GsColor c1, GsColor c2, float amount)
 {
     return(Interpolate(c1, c2, amount, SmoothStep));
 }
Пример #5
0
 public static GsColor Lerp(GsColor c1, GsColor c2, float amount)
 {
     return(Interpolate(c1, c2, amount, Lerp));
 }
Пример #6
0
 public static GsColor Darken(this GsColor color, float amt = 0.5f)
 {
     return(GsMath.Lerp(color, GsColor.Black, amt));
 }
Пример #7
0
 public static GsColor Lighten(this GsColor color, float amt = 0.5f)
 {
     return(GsMath.Lerp(color, GsColor.White, amt));
 }
Пример #8
0
 public GsColor(GsColor rgb, byte a)
     : this(a, rgb.R, rgb.G, rgb.B)
 {
 }
 public static void FillRectangle(this IGsGraphics graphics, GsColor color, GsRectangle rect)
 {
     graphics.FillRectangle(color, rect.X, rect.Y, rect.Width, rect.Height);
 }
Пример #10
0
        public static void DrawString(this IGsGraphics graphics, GsFont font, string text, float x, float y, float width, float height, GsColor color, GsAlignment alignment)
        {
            var size = GsTextMeasurer.MeasureString(font, text);
            var pos  = CalculatePosition(size, x, y, width, height, alignment);

            graphics.DrawString(font, text, pos.X, pos.Y, color);
        }