package com.nokia.common.excel.entity;

import java.awt.Color;

/**
 * 双色渐进色
 */
public class TwoColorGradient implements Gradient {

    // 两种颜色 默认双色 FF63BE7B--FFF8696B 红/绿
    private Color startColor = new Color(99, 190, 123, 255);
    private Color endColor = new Color(248, 105, 107, 255);

    // 开始数、截止数
    private double startValue;
    private double endValue;

    @Override
    public Color getColor(double d) {
        double t = (d - startValue) / (endValue - startValue);
        double red = (1 - t) * startColor.getRed() + t * endColor.getRed();
        double green = (1 - t) * startColor.getGreen() + t * endColor.getGreen();
        double blue = (1 - t) * startColor.getBlue() + t * endColor.getBlue();
        double opacity = (1 - t) * startColor.getAlpha() + t * endColor.getAlpha();
        return new Color((int) red, (int) green, (int) blue, (int) opacity);
    }
}
