p5js Prototype and Algorithm


Before I began prototyping in p5, I was lucky to be able to follow a few of Dan Shiffman’s Coding Train tutorials on the traveling salesman problem. I’ll be using Dan’s distance algorithm for my installation. I got Dan’s code working, which you can see in the image below. 512 is the path distance measured in pixels. The purple path on top is the one that has the shortest total distance, and the white path below is the current path being tested. It’s a brute-force algorithm, so every single possible path is tested in order to find the optimal route.

In office hours I asked him if it made sense to run the algorithm concurrently with my flower visualization program, and he suggested that I hard code the flower positions and store the optimal distance beforehand to make my life easier.

Now that I didn’t have to worry about the algorithm, I was able to start the fun part: designing a p5 prototype that a user could interact with! My goal is to get data on the flower path from the arcade buttons, but in the meantime I wrote a function to test for mouse clicks on the flowers (represented by colorful dots).

Here is my wishlist for my javascript program:

  • User inputs for name (aka worker bee name), class (aka your hive), and attempt number
  • Save path order and distance to a JSON file
  • Compare Button to display all path attempts side by side
  • Restart Pollination Training Button

Leave a Reply

Your email address will not be published. Required fields are marked *