I think this might look even cooler if you weighted the point selection a little so the intersections got sparser as you got further away from the center (so it might look more like a real city).
Looking at your algorithm (haven't read the code though) it seems like it would be super easy to do & it shouldn't affect the efficiency significantly.
I don't see why not. Each time you create a road that intersects two others do a flood fill on either side of that road. If either of the areas filled is too small then remove the road.
You don't have to flood fill, since you have the vector data you can just add random points like it is currently doing, but check what's the polygon enclosing said point and calculate its area (it is trivial if you divide the polygon in triangles).
It's probably trivial, true--but it's probably also very time-consuming, and I'm an impatient person! When it's not drawing hundreds of frames, the program takes about ten seconds to make a 1,000-point network, around two minutes to make a 10,000-point network, and around 1.5 hours to make a 100,000-point network--but I imagine that it'd take a lot longer if it had to make polygons and triangles out of all the segments.
Of course, that's a great deal more efficient. That was my first thought as well, but I had a brainfart figuring out how to go about that, so I didn't suggest it.
You're thinking in terms of an integer-based grid--but this isn't a grid, it's just a floating-point unit square, and I can't (or don't know how to, at least) use flood fill without a grid.
Program: PerpendicularDungeonNew
Network attributes: 1001 points, 1400 segments
Image attributes: 1000×1000 pixels, 2 pixels/segment; 539 frames, 200 ms/frame
Procedure:
0. Place two points at random locations in the unit square and connect them with a segment.
1. Place a point at a random location in the unit square.
2. Connect the new point to the network with the shortest possible segment--i.e., perpendicularly to an existing segment if possible, or obliquely to an existing point otherwise.
3. If possible, extend the new segment forwards (past the new point) until it intersects another pre-existing segment.
4. Repeat steps 1-3 until the network contains at least the desired number of intersections.
The approach of making a zillion lines at once, rather than just one, is very interesting--but I think my version looks just as geometrically nice (if less colorful) without being so extremely complicated. (Also, I'm just a n00b at programming.)
Note also that, because Substrate does everything incrementally, all its intersections are fuzzy and approximate--it's not really built to serve as a road network, while my version exports out the attributes of every line segment and every point, from which the network can be used in another program if necessary.
8
u/ToaKraka Sep 17 '14
Also, here's a 10,000-point static image, using the same algorithm. (Drawing all those frames really slows down the program...)
12
u/scribblenose Sep 17 '14
Looks nice, only thing I would suggest is discarding a new segment if it is too close to another parallel segment.
5
u/[deleted] Sep 17 '14 edited Sep 17 '14
What random algorithm are you using? I'd go with poisson disc to have more evenly distributed points (e.g compare random and poisson: http://devmag.org.za/2009/05/03/poisson-disk-sampling/)
Edit: fixed broken link
2
u/JanitorMaster Sep 17 '14
How do you do it? I've been looking for something like this.
2
u/dioderm Sep 17 '14
Your roads are awfully straight. I might throw in a curved road occasionally.
I am curious of what algorithm you are using as well!
3
u/asd33 Sep 17 '14
It reminds me more of a fields than roads. Nice algorithm though.
5
u/Coopsmoss Sep 17 '14
What an awful city to navigate