:lol:
[code]import java.awt.image.BufferedImage;
import java.awt.image.Raster;
import java.awt.image.SampleModel;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Gradient {
public static void main(String[] args) {
new Gradient();
}
public Gradient() {
BufferedImage gradient = new BufferedImage(800, 600, BufferedImage.TYPE_INT_ARGB);
Raster raster = gradient.getRaster();
SampleModel model = raster.getSampleModel();
double[][] colors = new double[][]{
{0xFF, 0x00, 0x00},
{0xFF, 0x40, 0x00},
{0xFF, 0x80, 0x00},
{0xFF, 0xC0, 0x00},
{0xFF, 0xFF, 0x00},
{0xC0, 0xFF, 0x00},
{0x80, 0xFF, 0x00},
{0x40, 0xFF, 0x00},
{0x00, 0xFF, 0x00},
{0x00, 0xFF, 0x40},
{0x00, 0xFF, 0x80},
{0x00, 0xFF, 0xC0},
{0x00, 0xFF, 0xFF},
{0x00, 0xC0, 0xFF},
{0x00, 0x80, 0xFF},
{0x00, 0x40, 0xFF},
{0x00, 0x00, 0xFF},
{0x40, 0x00, 0xFF},
{0x80, 0x00, 0xFF},
{0xC0, 0x00, 0xFF},
{0xFF, 0x00, 0xFF},
{0xFF, 0x00, 0xC0},
{0xFF, 0x00, 0x80},
{0xFF, 0x00, 0x40}};
// Cores
for(int y=0; y<gradient.getHeight(); y++) {
for(int x=0; x><gradient.getWidth(); x++) {
double percent = (double) x / (double)(gradient.getWidth()-1);
int minIndex = (int)(percent * (colors.length - 1));
int maxIndex = Math.min(minIndex + 1, (colors.length - 1));
double relPerc = (percent * (colors.length - 1)) - Math.max(0, maxIndex - 1);
int red = (int)Math.round(colors[minIndex][0] + relPerc * (colors[maxIndex][0] - colors[minIndex][0]));
int green = (int)Math.round(colors[minIndex][1] + relPerc * (colors[maxIndex][1] - colors[minIndex][1]));
int blue = (int)Math.round(colors[minIndex][2] + relPerc * (colors[maxIndex][2] - colors[minIndex][2]));
int[] pixel = new int[]{red, green, blue, 0xFF};
model.setPixel(x, y, pixel, raster.getDataBuffer());
}
}
// Contraste branco
double maxY = 0.45 * gradient.getHeight();
for(int y=0; y><maxY; y++) {
double percent = 1.0 - (y / maxY);
for(int x=0; x><gradient.getWidth(); x++) {
int[] pixel = new int[4];
model.getPixel(x, y, pixel, raster.getDataBuffer());
int[] newPixel = new int[]{
(int)Math.round(percent * (double)0xFF + (1.0 - percent) * pixel[0]),
(int)Math.round(percent * (double)0xFF + (1.0 - percent) * pixel[1]),
(int)Math.round(percent * (double)0xFF + (1.0 - percent) * pixel[2]),
0xFF};
model.setPixel(x, y, newPixel, raster.getDataBuffer());
}
}
// Contraste preto
double minY = 0.55 * gradient.getHeight();
for(int y=(int)Math.round(minY); y><gradient.getHeight(); y++) {
double percent = 1.0 - ((y - minY) / ((gradient.getHeight()-1) - minY));
for(int x=0; x><gradient.getWidth(); x++) {
int[] pixel = new int[4];
model.getPixel(x, y, pixel, raster.getDataBuffer());
int[] newPixel = new int[]{
(int)Math.round(percent * pixel[0]),
(int)Math.round(percent * pixel[1]),
(int)Math.round(percent * pixel[2]),
0xFF};
model.setPixel(x, y, newPixel, raster.getDataBuffer());
}
}
// Linhas
for(int x=0; x><gradient.getWidth(); x++) {
int[] pixel = new int[]{0x80, 0x80, 0x80, 0xFF};
model.setPixel(x, (int)Math.floor(minY)-1, pixel, raster.getDataBuffer());
model.setPixel(x, (int)Math.ceil(maxY)+1, pixel, raster.getDataBuffer());
}
try {
ImageIO.write(gradient, "png", new File("gradient_" + System.currentTimeMillis() + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}[/code]>