Files
CodeChickenCore/codechicken/lib/colour/CustomGradient.java
T

33 lines
970 B
Java
Raw Normal View History

2013-07-16 17:58:02 +10:00
package codechicken.lib.colour;
import codechicken.lib.math.MathHelper;
import codechicken.lib.render.TextureUtils;
2014-04-09 13:38:05 +10:00
import net.minecraft.util.ResourceLocation;
import java.awt.image.BufferedImage;
2013-07-16 17:58:02 +10:00
public class CustomGradient
{
public int[] gradient;
public CustomGradient(ResourceLocation textureFile)
{
BufferedImage img = TextureUtils.loadBufferedImage(textureFile);
int[] data = new int[img.getWidth()];
img.getRGB(0, 0, img.getWidth(), 1, data, 0, img.getWidth());
gradient = new int[img.getWidth()];
for(int i = 0; i < data.length; i++)
gradient[i] = (data[i]<<8)|(((data[i])>>24)&0xFF);
}
public ColourRGBA getColour(double position)
{
return new ColourRGBA(getColourI(position));
}
public int getColourI(double position)
{
int off = (int)MathHelper.clip(gradient.length*position, 0, gradient.length-1);
return gradient[off];
}
}