Lerp between two color - CSharp System.Drawing

CSharp examples for System.Drawing:Color

Description

Lerp between two color

Demo Code


using System.Drawing;
using System;/*  w  w  w.jav a  2  s. c o  m*/

public class Main{
        public static Color Lerp(this Color s, Color t, float k)
        {
            var bk = (1 - k);
            var a = s.A * bk + t.A * k;
            var r = s.R * bk + t.R * k;
            var g = s.G * bk + t.G * k;
            var b = s.B * bk + t.B * k;
            return Color.FromArgb((int) a, (int) r, (int) g, (int) b);
        }
}

Related Tutorials