What to do with imports when converting for browser?

I'm trying to host a project of mine on the web so that I can Easily show it off to friends and coworkers. I thankfully saw here that you can't have any imports in your code in order for it work in browser. I use two Util.* classes for my project, Arrays and Map. I know I can replace Arrays, because I only use its toString() method, but What can I do about Map? Is there anything that can be done make my project web friendly? I'll add the import declaration, but for readability's sake, as there are multiple files, here's the git

float squareX;
float squareY;
Camera worldCam;
import java.util.Arrays;
import java.util.Map;

int speed;
Button startButton;
Button pausePlayButton;
Button speedUpButton;
Button speedDownButton;
TextDisplay speedDisplay;
Field field;

boolean start;
boolean isDrawing;

void settings(){
   size(1600, 900);
}

void setup(){
   worldCam = new Camera();
   speed = 1;
   frameRate(30 * speed);
   noStroke();

   field = new Field(25);

   //Params                   Name  Gender MaxAge   Size                            ColorOne                                    ColorTwo                          PetalOne                      PetalTwo
   field.addFlower(new Flower("Adam", 'M', 60, new Genotype(60, 1.0), new Genotype(new int[] {187, 187, 0}, 1.0), new Genotype(new int[] {187, 187, 0}, 1.0), new Genotype("square", 1.0), new Genotype("square", 1.0)));
   field.addFlower(new Flower("Eve", 'F', 120, new Genotype(45, 0.5), new Genotype(new int[] {255, 187, 187}, 0.5), new Genotype(new int[] {255, 187, 187}, 0.5), new Genotype("round", 0.66), new Genotype("triangle", 0.33)));
   field.addFlower(new Flower("Lillith", 'F', 70, new Genotype(51, 1.0), new Genotype(new int[] {20, 217, 197}, 1.0), new Genotype(new int[] {0, 50, 187}, 0.5), new Genotype("square", 1.0), new Genotype("triangle", 0.33)));

   //Params               startX, startY, Width, Height, Text
   startButton = new Button(50, 10, 130, 30, "Start");
   pausePlayButton = new Button(230, 10, 130, 30, "Pause");
   speedDownButton = new Button(width-275, 10, 50, 30, "<<");
   speedUpButton = new Button(width-125, 10, 50, 30, ">>");
   speedDisplay = new TextDisplay(speed, width-200, 10, 50, 30);

   isDrawing = true;
}

void draw(){
   background(99, 209, 62);

   fill(125,125,125);
   rect(0, 0, width, 50);

   startButton.draw();
   pausePlayButton.draw();

   fill(35,35,35);
   rect(width-300, 5, 250, 40);
   speedDownButton.draw();
   speedDisplay.draw();
   speedUpButton.draw();

   translate(-worldCam.pos.x, -worldCam.pos.y);
   worldCam.draw();

   if(start){
      field.drawFlowers(); 
   }
}
Tagged:

Answers

  • edited November 2017

    You can create your own Map-like classes to replace that Map

    Here what you can do:

    class MyMap<K,V>{
    
        private Array<K> keys;
        private Array<V> values;
    
        public MyMap(){
            keys = new Array();
            values = new Array();
        }
    
        public void put(K key,V value){
            keys.add(key);
            values.add(value);
        }
    
        public V get(K key){
            // Loop through each keys and return the value
        }
    
    }
    

    and so on. But you will need to recreate all of the methods you will use from the Map of java.util.*

    Hope you get the idea. Best regards :D.

  • edited November 2017 Answer ✓

    ... but what can I do about Map?

    Class HashMap is available on Pjs, as you can see from the link below: ;)
    http://ProcessingJS.org/reference/HashMap/

  • it looks like you are only using Map in your Flower class and then only for a limited set of known entries

    genes = new HashMap<String, Chromosome>();
    genes.put("color", new Chromosome(c1, c2));
    genes.put("size", new Chromosome(s, s));
    genes.put("petal", new Chromosome(p1, p2));
    genes.put("mutability", new Chromosome(new Genotype(0.01, 1), new Genotype(0.02, 1)));
    

    so a map isn't necessarily a good match for this use case anyway - it could just be a new class holding those 4 things

Sign In or Register to comment.