-1
\$\begingroup\$

This question already has an answer here:

This is a successor to my previous Code Golf challenge, which may be found here.

This time, you are trying to determine what the contents of colors.txt should be.

Your task is to take from the input the path to an image and a number of colours, and write to colors.txt a list of that many colors chosen for that image.

Remember, you are generating pallettes to go with this challenge.

As usual, you are going for lowest score, but in this case, your score is given by ceil(codeSize/(1+max(0,votes))), so upvotes will help you as well.

For one or more of the following images, you should test your generated pallettes (using one of the answers from this challenge to test them) and post the results for a variety of pallette sizes: enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

\$\endgroup\$

marked as duplicate by Alex A., es1024, Community May 19 '15 at 1:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    \$\begingroup\$ Apart from lifting the restriction that on the number of contiguous cells in the result, this seems to be asking for the same as Paint by Numbers. \$\endgroup\$ – Martin Ender May 18 '15 at 23:09
  • \$\begingroup\$ So, do you think this should be deleted in that case? \$\endgroup\$ – SuperJedi224 May 19 '15 at 0:26
1
\$\begingroup\$

Java

796 bytes

import java.awt.Color;import java.awt.image.*;import java.io.*;import java.util.*;import javax.imageio.*;public class P{public static void main(String[] a) throws Exception{Random R=new Random();Scanner in=new Scanner(System.in);PrintStream o=new PrintStream("colors.txt");List<Color> col=new ArrayList<Color>();BufferedImage i=ImageIO.read(new File(in.nextLine()));int h=i.getHeight(),w=i.getWidth(),k=in.nextInt(),x,y,z=0,r,g,b;while(col.size()<k&&z<k*k){x=R.nextInt(w);y=R.nextInt(h);Color c=new Color(i.getRGB(x, y));r=5*(c.getRed()/5);g=5*(c.getGreen()/5);b=5*(c.getBlue()/5);c=new Color(r,g,b);if(!col.contains(c)){col.add(c);}z++;}while(col.size()<k)col.add(new Color(R.nextInt(256),+R.nextInt(256),R.nextInt(256)));for(Color c:col)o.println(c.getRed()+" "+c.getGreen()+" "+c.getBlue());}}

Picks random colors from the image, with each component rounded to the nearest multiple of 5, such that no color is selected twice. If, after n2 selections, it has not yet found n distinct colors, it picks the rest entirely at random.

Some sample results:

The black spaceship in 10 colors: enter image description here

In 25 colors: enter image description here

In 50 colors: enter image description here

In 200 colors: enter image description here

The gold spaceship in 10 colors:

enter image description here

In 25 colors:

enter image description here

In 50 colors:

enter image description here

In 200 colors:

enter image description here

And, finally, the exploding globe in 10 colors: enter image description here

In 25 colors: enter image description here

In 50 colors: enter image description here

And in 200 colors: enter image description here

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.