0

I am currently coding a java applet to visual a modified version of breadth first search.

My problem is I am trying to convert a number coordinated to a pixel on a 2d array to a color.

Code : map is a 2d array of values that should be increasing by 1 as they go away from the starting location except for walls which are set to 0 and will appear as black.

String colorhex1 = Integer.toHexString(map[i][j]+100);

g.setColor(Color.decode("#"+colorhex1));
if (map[i][j]==1)
    g.setColor(Color.white);
else if (map[i][j]==0)
    g.setColor(Color.Black);

g.fillRect(i*10,j*10+40,10,10);

How the main search works is it increases the number of each cell next to it one unless it has been touched so in my visualization it should show a increase in vibrancy as we get farther away from the starting location. However with this design I have currently it will one start off as "black" which is the color of my walls. To which then two it will slowly head towards purple then randomly change color then again and again having it look quite weird.

Question : Is there a way for me to code a more gradual way of increasing this color by using the number value of the map array?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    FYI: [Java Plugin support deprecated](http://www.gizmodo.com.au/2016/01/rest-in-hell-java-plug-in/) and [Moving to a Plugin-Free Web](https://blogs.oracle.com/java-platform-group/entry/moving_to_a_plugin_free) – MadProgrammer Apr 22 '16 at 00:19
  • *"Is there a way for me to code a more gradual way of increasing this color by using the number value of the map array?"* Probably, some context might help though. You might be able to use something like [this](http://stackoverflow.com/questions/21744672/set-color-dynamically-based-on-value-java-swing/21744789#21744789) which is based on [this](http://stackoverflow.com/questions/13223065/color-fading-algorithm/13223818#13223818) and [this](http://stackoverflow.com/questions/21270610/java-smooth-color-transition/21270957#21270957) – MadProgrammer Apr 22 '16 at 00:20

0 Answers0