Show HN: Random Roads
11–20 of 52 posts
Re: Show HN: Random Roads
#12Being able to see the random seed used in the console and use it in the hash is a nice touch. I found a few large ones and one with a single path between two points (1592751582695)
I enjoy the large ones (eg. https://random-roads--edwardcunningh2.repl.co/#1589058113269) where I imagine the gaps left in the middle to be parks.
Re: Show HN: Random Roads
#13Re: Show HN: Random Roads
#14Hey, good work! What algorithm did you use?
It's not especially clever:
1. I define a set of possible moves (eg. straight ahead, left turn, junction, etc). One possible move is a dead-end, which looks a bit like a house in my interpretation.
2. Each move is assigned a relative weight (eg. continuing straight ahead 10x more likely than turning left).
3. Each iteration, for each of the roads under construction, a random move is selected. Some moves are impossible (based on other roads already drawn on the map) and so it will ensure not to select one that would result in a collision. At worst, it will terminate the road with a dead-end.
4. Repeat forever, until every road has terminated in a dead-end.
Most of the script itself is dealing with the rendering logic. To avoid collisions I maintain a 2D array of all visited points.
Re: Show HN: Random Roads
#15Oddly mesmerising. What did you use to do it?
I did investigate JS 2D graphics libraries but decided in the end that this was sufficiently simple to not warrant one. It was harder than I expected to get the drag & zoom to work!
Re: Show HN: Random Roads
#16Re: Show HN: Random Roads
#17Thanks for sharing! Really like the minimal design and the animations. Could you explain how you did this simulation?
I wrote a brief description in this comment: https://news.ycombinator.com/item?id=23592538
Initially I had envisaged something a bit cleverer, but for an art project keeping it simple seemed to do the trick.
Re: Show HN: Random Roads
#18this one seems to show the boundaries of the display plane : https://random-roads--edwardcunningh2.repl.co/#1592753917190
Re: Show HN: Random Roads
#19This reminds me of the beautiful "substrate" screen saver: http://www.complexification.net/gallery/machines/substrate/
Re: Show HN: Random Roads
#20Interesting. this one seems to show the boundaries of the display plane : https://random-roads--edwardcunningh2.repl.co/#1592753917190
It is artificially limited to a 1001 x 1001 grid - just to stop it from growing forever (which could get quite slow on lower end devices). In practice I rarely encounter maps that go that far.