We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › simple color sorter that used to work
Page Index Toggle Pages: 1
simple color sorter that used to work (Read 916 times)
simple color sorter that used to work
Oct 30th, 2008, 10:14pm
 
Hello, I'm working on a pretty simple little guy. It used to work in 0135. I've looked through the revisions and can't find why I'd be getting this error:


Exception in thread "Animation Thread" java.lang.NullPointerException

at java.lang.String.compareTo(String.java:998)

at java.lang.String.compareTo(String.java:90)

at java.util.Arrays.mergeSort(Arrays.java:1156)

at java.util.Arrays.mergeSort(Arrays.java:1168)

at java.util.Arrays.mergeSort(Arrays.java:1168)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.mergeSort(Arrays.java:1167)

at java.util.Arrays.sort(Arrays.java:1118)

at processing.core.PApplet.sort(PApplet.java:4495)

at processing.core.PApplet.sort(PApplet.java:4488)

at colorPhotoHex.setup(colorPhotoHex.java:30)

at processing.core.PApplet.handleDraw(PApplet.java:1372)

at processing.core.PApplet.run(PApplet.java:1300)

at java.lang.Thread.run(Thread.java:613)





HERE'S THE CODE:

String[] Colors = new String[width*height];
PImage photo;
int count = 0;

size(4, 4);

photo= loadImage("photos/birch02.gif");
image(photo, 0, 0);
loadPixels();

for (int i = 0; i<pixels.length; i++){
 String hVal = hex(pixels[i]);
 Colors[i] = hVal;
 }
Colors = sort(Colors);


 for(int h=0; h<height; h++){
   for(int w=0; w<width; w++){
    color colorVal = unhex(Colors[count]);
    //println(colorVal);
    stroke(colorVal);
    point(w,h);
    count++;  
    }
  }

save("colorSamples/" + photo + ".jpg");


Any help would be greatly appreciated
Re: simple color sorter that used to work
Reply #1 - Oct 31st, 2008, 12:40am
 
i get an array out of bounds exception on the

Colors[i] = hVal;  

line with i = 10,000. this is because width x height in the first line default to 100 x 100 before the size() call changes them (i made it 320x240 as that's how big my image was)

if i make the size 100x100 it's fine

if i make size 4x4 then Colors is still 100x100 but everything beyond Colors[4][4] is uninitialised, which is why the sort fails.

i would define WIDTH and HEIGHT myself and use them throughout

final int LENGTH = 4;
final int WIDTH = 4;
String[] Colors = new String[WIDTH * HEIGHT];

and

size(WIDTH, HEIGHT);

and also in the two for loops.

seems to work. i don't think the sort of colours does what you think it will though.
Re: simple color sorter that used to work
Reply #2 - Nov 1st, 2008, 11:25pm
 
I'll give it a try, thanks for the help
Page Index Toggle Pages: 1