如何做到这一点渐变颜色生成? [英] How to do that Gradient Color Generator?

查看:177
本文介绍了如何做到这一点渐变颜色生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能产生16种颜色。我首发的颜色是红,我的终端颜色卡其。我要插入14色。但它看起来像梯度流动。 Forexample color.Black并非来自红。暴力应该冲红。

How can i generate 16 color. my starter color is "Red" and my terminal color "khaki". i have to insert 14 color. But it looks like gradient flow. Forexample color.Black does not come from red. Violent should come red from red.

推荐答案

您应该能够插值?这个例子是的WinForms,但数学是相同的 - 只是与ASP.NET,你就得写在十六进制形式的颜色。你也可以(与ASP.NET)需要分别找到RGB值 - 但对信息,卡其色(在的WinForms)为{240230140}(红色,显然{} 255,0,0)

You should be able to interpolate? This example is winforms, but the maths is identical - simply that with ASP.NET you'd have to write the color in the hex form. You may also (with ASP.NET) need to find the RGB values separately - but for info, Khaki (in winforms) is {240,230,140} (red is obviously {255,0,0}).

using System.Drawing;
using System.Windows.Forms;

static class Program {
    static void Main()
    {
        Form form = new Form();
        Color start = Color.Red, end = Color.Khaki;
        for (int i = 0; i < 16; i++)
        {
            int r = Interpolate(start.R, end.R, 15, i),
                g = Interpolate(start.G, end.G, 15, i),
                b = Interpolate(start.B, end.B, 15, i);

            Button button = new Button();
            button.Dock = DockStyle.Top;
            button.BackColor = Color.FromArgb(r, g, b);
            form.Controls.Add(button);
            button.BringToFront();
        }

        Application.Run(form);
    }
    static int Interpolate(int start, int end, int steps, int count)
    {
        float s = start, e = end, final = s + (((e - s) / steps) * count);
        return (int)final;
    }    
}

这篇关于如何做到这一点渐变颜色生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆