⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorgradient.java

📁 JAVA 反走样画直线 可在JAVA1.1下使用
💻 JAVA
字号:
///////////////////////////////////////////////////////////
// DeJaved by mDeJava v1.0. Copyright 1999 MoleSoftware. //
//       To download last version of this software:      //
//            http://molesoftware.hypermatr.net          //
//               e-mail:molesoftware@mail.ru             //
///////////////////////////////////////////////////////////

import java.awt.Color;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Hashtable;

public class ColorGradient
{

    protected Hashtable gradient = null;

    public ColorGradient()
    {
        gradient = new Hashtable();
    }

    public ColorGradient(Color color, Color color1)
    {
        gradient = new Hashtable();
        setColor(0.0D, color);
        setColor(1.0D, color1);
    }

    public Color getColor(double d)
    {
        double d1 = 0.0D;
        double d2 = 1.0D;
        for(Enumeration enumeration = gradient.keys(); enumeration.hasMoreElements();)
        {
            double d3 = ((Double)enumeration.nextElement()).doubleValue();
            if(d3 <= d && d3 > d1)
                d1 = d3;
            else
            if(d3 >= d && d3 < d2)
                d2 = d3;
        }

        Color color = (Color)gradient.get(new Double(d1));
        Color color1 = (Color)gradient.get(new Double(d2));
        if(color == null && color1 == null)
        {
            System.err.println("No colors found in ColorGradient " + gradient);
            System.err.println("Returning Color.black. ");
            return Color.black;
        }
        if(color == null)
            return color1;
        if(color1 == null)
            return color;
        float f = (float)(d2 - d1);
        float f1 = (float)(d - d1);
        if((double)f == 0.0D)
        {
            return color;
        }
        else
        {
            float f2 = (float)color.getRed() / 255F;
            float f3 = (float)color.getGreen() / 255F;
            float f4 = (float)color.getBlue() / 255F;
            float f5 = (float)color1.getRed() / 255F;
            float f6 = (float)color1.getGreen() / 255F;
            float f7 = (float)color1.getBlue() / 255F;
            float f8 = f2 + (f1 * (f5 - f2)) / f;
            float f9 = f3 + (f1 * (f6 - f3)) / f;
            float f10 = f4 + (f1 * (f7 - f4)) / f;
            return new Color(f8, f9, f10);
        }
    }

    public void setColor(double d, Color color)
    {
        gradient.put(new Double(d), color);
    }

    public String toString()
    {
        StringBuffer stringbuffer = new StringBuffer();
        double d;
        Color color;
        for(Enumeration enumeration = gradient.keys(); enumeration.hasMoreElements(); stringbuffer.append("(" + d + ", " + color + ") "))
        {
            d = ((Double)enumeration.nextElement()).doubleValue();
            color = (Color)gradient.get(new Double(d));
        }

        return stringbuffer.toString();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -