##Java
Variations of a color picker in 512x512. Elegant code it is not, but I do like the pretty pictures:
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
public class EighteenBitColors {
static boolean shuffle_block = false;
static int shuffle_radius = 32;
public static void main(String[] args) {
BufferedImage img = new BufferedImage(512, 512, BufferedImage.TYPE_INT_RGB);
for(int r=0;r<64;r++)
for(int g=0;g<64;g++)
for(int b=0;b<64;b++)
img.setRGB((r * 8) + (b / 8), (g * 8) + (b % 8), ((r * 4) << 8 | (g * 4)) << 8 | (b * 4));
if(shuffle_block)
blockShuffle(img);
else
shuffle(img, shuffle_radius);
try {
ImageIO.write(img, "png", new File(getFileName()));
} catch(IOException e){
System.out.println("suck it");
}
}
public static void shuffle(BufferedImage img, int radius){
if(radius < 1)
return;
int width = img.getWidth();
int height = img.getHeight();
Random rand = new Random();
for(int x=0;x<512;x++){
for(int y=0;y<512;y++){
int xx = -1;
int yy = -1;
while(xx < 0 || xx >= width){
xx = x + rand.nextInt(radius*2+1) - radius;
}
while(yy < 0 || yy >= height){
yy = y + rand.nextInt(radius*2+1) - radius;
}
int tmp = img.getRGB(xx, yy);
img.setRGB(xx, yy, img.getRGB(x, y));
img.setRGB(x,y,tmp);
}
}
}
public static void blockShuffle(BufferedImage img){
int tmp;
Random rand = new Random();
for(int bx=0;bx<8;bx++){
for(int by=0;by<8;by++){
for(int x=0;x<64;x++){
for(int y=0;y<64;y++){
int xx = bx*64+x;
int yy = by*64+y;
int xxx = bx*64+rand.nextInt(64);
int yyy = by*64+rand.nextInt(64);
tmp = img.getRGB(xxx, yyy);
img.setRGB(xxx, yyy, img.getRGB(xx, yy));
img.setRGB(xx,yy,tmp);
}
}
}
}
}
public static String getFileName(){
String fileName = "allrgb_";
if(shuffle_block){
fileName += "block";
} else if(shuffle_radius > 0){
fileName += "radius_" + shuffle_radius;
} else {
fileName += "no_shuffle";
}
return fileName + ".png";
}
}
As written, it outputs:
If you run it with shuffle_block = true
, it shuffles the colors in each 64x64 block:
Else, if you run it with shuffle_radius > 0
, it shuffles each pixel with a random pixel within shuffle_radius
in x/y. After playing with various sizes, I like a 32 pixel radius, as it blurs the lines without moving stuff around too much: