Trying to dynamically name & create Hashmaps inside of a Hashmap
in
Programming Questions
•
2 years ago
I'm trying to take the RGB value of pixels make them into hashmaps, inside of a hashmap. However, I cannot figure out how to dynamically create hashmaps. I tried converting the hashmap to a string and then inserting it as a key in the master hashmap, but then I have not created a hashmap inside of the master.
There must be a way to do this
- HashMap hm=new HashMap();
- HashMap library=new HashMap(); // Master HashMap
- PImage src;
- PImage dstn;
- void setup() {
- size(10, 10);
- src = loadImage("plus.jpg");
- dstn = createImage(src.width, src.height, RGB);
- }
- void draw() {
- color temp = (0);
- src.loadPixels();
- src.loadPixels();
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- int loc = x + y*width;
- color d = src.get(2,5);
- dstn.pixels[loc] = color(d);
- temp = d;
- }
- }
- dstn.updatePixels();
- image(dstn,0,0);
- HashMap current_pixel = hm; // assign the current pixel a hashmap
- if (library.containsKey(current_pixel)) { // if library has entry for current pixel
- int val = ((Integer) library.get(current_pixel)).intValue(); //accumulator
- library.put(current_pixel, new Integer(val + 1)); // add 1 to
- }
- else {
- library.put(current_pixel,0); //adds entry & a value of 1 if entry does not exist
- }
- String neigh = "255,0,0"; // variable of neighbor pixel
- if (current_pixel.containsKey(neigh)) { // if neighbor pixel is in hashmap -
- int val = ((Integer) current_pixel.get(neigh)).intValue(); //accumulator
- current_pixel.put(neigh, new Integer(val + 1));
- }
- else {
- current_pixel.put(neigh,1); //adds entry & a value of 1 if entry does not exist
- }
- println(library);
- println(round(red(temp)) + "," + round(green(temp)) + "," + round(blue(temp)));
- }
I appreciate an help
1