Created
December 5, 2016 18:05
-
-
Save DrPlantabyte/399825cda84dbf2d04110c4beafbecd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color; | |
import java.awt.image.BufferedImage; | |
import java.io.IOException; | |
import java.nio.file.Paths; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.imageio.ImageIO; | |
import javax.swing.ImageIcon; | |
import javax.swing.JLabel; | |
import javax.swing.JOptionPane; | |
/** | |
* Makes a palette image to use in GIMP or something | |
* @author CCHall | |
*/ | |
public class ColorPaletteMaker { | |
public static void main(String[] args){ | |
// 12 hues * 3 saturation values * 5 values = 180 colors | |
int numHues = 12; | |
int numSaturations = 4; | |
int numShades = 5; | |
int width = numShades * numSaturations; | |
int height = numHues; | |
BufferedImage bimg = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB); | |
for(int h = 0; h < numHues; h++) | |
for(int s = 0; s < numSaturations; s++) | |
for(int v = 0; v < numShades; v++){ | |
int y = h; | |
int x = s * numShades + v; | |
float hue = (float)h / (float)(numHues); | |
float sat = (float)s / (float)(numSaturations - 1); | |
float val = (float)v / (float)(numShades - 1); | |
bimg.setRGB(x, y, Color.HSBtoRGB(hue, sat, val)); | |
} | |
JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(bimg))); | |
try { | |
ImageIO.write(bimg, "png", Paths.get("palette.png").toFile()); | |
} catch (IOException ex) { | |
Logger.getLogger(ColorPaletteMaker.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment