PDA

View Full Version : Gimp Plugin: A better lazy man's city?



Alfar
08-07-2009, 08:12 AM
Inspired by the mosaic city building stuff (torstan's tute here, e.g. (http://forum.cartographersguild.com/showthread.php?t=3392)), I made a script to do the same, but working with something that resembles Voronoi patterns. My understanding of the concept may be lacking, but I've found that radial gradients placed against eachother using lighten only will make for some nice straightish lines when you edge detect it.

To use, make a b/w map of your streets (streets black, house areas white), then make a selection of the areas you want to populate with houses and activate the plugin (under Filters|Map tools|Generate city)

I've attached an example where I've made a couple of different areas with different sized buildings and colors.

Comments and ideas are welcome. I've considered making a setting for increasing the distance between houses.

Edit: I added the setting for distance between houses.

Sigurd
08-07-2009, 11:48 AM
looks good.

Any way you can hollow out the center shapes automatically?

ie. create courtyards

RobA
08-07-2009, 11:57 AM
Moved to the actions forum.

Nice script (not that I know python). A suggestion is to use the enums provided rather than integers to make the code more readable. Like using FG-BG-RGB-MODE instead of 0.

-Rob A>

RobA
08-07-2009, 12:32 PM
OK - noticed a few oddities.

Instead of undo enable/disable, wrap the plugin code with gimp_image_undo_group_start and gimp_image_undo_group_end. THis will let you "undo" the plugin as one step, as it is now I can't undo the plugin.

You also leave a layer mask selected at the end. It is nicer to leave a layer selected.

An option to both merge visible and delete non-visible layers might be useful.

-Rob A>

ravells
08-07-2009, 01:16 PM
Looking good Alfar but too regular to my eye and that was the big problem I always came up against with the lazy man's style. But you've solved it for me with that context free script. What I love about it is that with a few tweaks you can create literally thousands of buildings which look simlar but not identical which really helps with a consistency of style.

Ascension
08-07-2009, 01:43 PM
You'll have to take me step by step thru this Ravs cuz I don't know the first thing about using CF...add that it to your tut maybe?

ravells
08-07-2009, 01:52 PM
Sure, no worries. Alfar's done all the hard work, it's just changing the odd number here or there. Let me finish this city first and then I'll get on with the full tut. Alfar's the best one to explain the context free end of it though.

Alfar
08-07-2009, 03:56 PM
looks good.

Any way you can hollow out the center shapes automatically?

ie. create courtyards

Yes, definately going to be an option. Do you want just one layer of houses, then?


OK - noticed a few oddities.

Instead of undo enable/disable, wrap the plugin code with gimp_image_undo_group_start and gimp_image_undo_group_end. THis will let you "undo" the plugin as one step, as it is now I can't undo the plugin.

You also leave a layer mask selected at the end. It is nicer to leave a layer selected.

An option to both merge visible and delete non-visible layers might be useful.

-Rob A>

I did use undo_group_start and undo_group_end, but I ran into trouble because I'm doing a huge number of gimp_edit_blend, and it just blows away memory on the undo info for some reason. I was going to ask you about that, actually.

I'll try and fix the selection at the end, and the two options you mention, sure thing.

I wonder if a house size jitter would help with the uniformity... will have to look into that. Maybe a placement jitter as well? Hmmm...

RobA
08-07-2009, 09:40 PM
Hmmm. I ran into a similar problem with my multifill script.
Is there a freeze/thaw call for undo?

Ultimately the solution I came up with was to copy the active layer then use the paste as new image pdb call, then disable the undo stack on the new image only when all the processing was done I did a copy paste back into the original image (that just has an undo group)

That might help?

-Rob A>

Alfar
08-08-2009, 12:49 AM
Ah, yes... doing the stuff in a different image would probably do the trick. Will have to play with that. Thanks!

Alfar
08-09-2009, 07:05 AM
A new version, with support for undo (Thanks for the tip RobA, ended up working on a copy, works great, probably even faster than before)

Added a courtyards option, which will make only one layer of houses, and cut out the middle. It makes for much more regularly shaped houses as well.

Added a delete invisible layers option (which doesn't actually delete anything, just doesn't copy them back over from the copy image)

Added a merge layers option, which (duh) merges the visible layers before moving them to the original image.

Also cleaned up some of the code to use constants rather than integers as advised by RobA. I know it's a good idea, I just had some trouble converting the constants from the documentation to their names in python at an early point when learning to write plugins and sorta gave up. Mostly all is good now, though, so will clean up the rest of the code in time.

Now for some jittering ;)

geoff_nunn
08-09-2009, 08:59 PM
Holy Crap! I love it! This is going to make it a bajillion times easier for me to finish my map of Turimor! Thanks! Have some rep and a post with lots of exclamation points!!!!!

ravells
08-10-2009, 12:43 AM
I don't have Gimp but would love to see some examples from your script! Jittering would be a fabulous idea!

Cheers

Ravs

Alfar
08-13-2009, 04:10 PM
Will make examples soonish... been playing with my town generator, trying to improve the houses it makes. Quite some success, I believe. Notice the rooftops being much sharper than what we usually achieve with the dimpled gradient.

I'm now stacking multiple gradients with various selections to generate the bump map. Only problem right now is overlapping houses, which I know how to fix, just haven't had the time.

I guess I may be able to do something like this, but with houses snugly against eachother - that'd be desirable for city work, yes?

Steel General
08-13-2009, 04:45 PM
Cool stuff all around, even if I don't use the GIMP...

Alfar
08-14-2009, 08:57 AM
Well, I'm not going to enter the competition, but I figured a lazy man's Oten-Jo would be kinda suitable as an example of the city generator as it lies.

For some reason or other, Gimp keeps crashing when I create images larger than, eh, 2000x2000 or so, so I ended up making a lo-res map for this demo. It does seem that the houses are at their best when I keep the size around 10-20. The larger houses get kinda wonky. I want a better solution, but I still think it's a step up from using Gimp's mosaic filter.