The Artist's Husband: City Map?

/2024/03/the-artists-husband-city-map/images/top_image.png

While working on another project (stay tuned!), I came up with this. It’s not what I was shooting for, but I think it’s kind of interesting. It looks a bit like a city street map from a time before urban planning.

What is going on here is that a single particle is placed on the canvas in a particular position and with a particular direction. At every iteration, the particle moves a small amount in its given direction. There is some random variation in the exact direction, but it ends up leaving a straight line, albeit a slightly wobbly one. Also at every iteration, there is a change that a new particle will be spawned and will branch off in a new direction, roughly 90 degrees from the previous particle’s path. A particles “dies” if its next position would leave the canvas or cross another line.

Just for grins, here’s what it looks like with no random direction variation. A very different effect!

/2024/03/the-artists-husband-city-map/images/no_direction_variation.png

There are a few problems in the implementation of this algorithm. A line should not touch another line other than where it branches off from one, but you can see in the images that they do touch. Assuming no worse problem that I haven’t spotted yet, the reason for this is that I am using an algorithm for collision detection between line segments. A line that doesn’t collide with another line. might still end on a pixel right next to that line. Mathematically they are not touching, but visually they are! This problem gets worse if I want to use a heavier line (I do!) So this is still a work in progress.

I’ve mentioned it before , but there is a great discussion on 2-dimensional collision detection by Jeff Thompson on his website . There are plenty of examples (in Processing ). It’s a great place to start if you need to know about collision detection (Spoiler Alert: if you are doing generative art, you are very likely going to need to understand collision detection!)

Other variables that affect the final image here are the distance a particle travels on each iteration (here set to 10, but this could be set to some other value, or could vary randomly within a range) and the probability of there being a new particle spawned (here set to be highly probable - about 90%.) These two would interact somewhat, since a longer step would result in fewer opportunities to spawn a branch before the particle hits something and dies.

I’ll let you know when I have this working like I want it to…