PDA

View Full Version : Need some programming help



ravells
07-15-2009, 03:12 AM
I'm doing a map commission and I need some passable outlines of larger buildings which are more than just rectangles. There is a free piece of software called 'context free' (http://www.contextfreeart.org/)which I think would allow one to make dozens of random shapes in a building-like form. Below are some examples I've taken from their gallery of the shapes it can generate.

The only problem is that I am not a natural coder. I suspect the code to produce black building silhouettes would not be difficult for someone who was used to writing code. I don't need the buildings to be organised in any particular way, I just need lots of buildings generated so I can pick the ones I like and drop them into photoshop.

Can anyone help?

Thanks in advance,

Ravs

Alfar
07-15-2009, 04:04 AM
Something like these?

The zip file is the Context Free script that produced them.

ravells
07-15-2009, 07:11 AM
You are an absolute angel! Thank you so much and have lots of rep!

Thank you, thank you!

Ravs

Alfar
07-15-2009, 07:34 AM
Most welcome. I found the exercise refreshing :)

Ascension
07-15-2009, 04:00 PM
That is uber cool. Guess I gotta download yet another must have tool.

töff
07-15-2009, 04:44 PM
@Alfar. Now use the Thatch tutorial to generate textures at 90° to the building edges. And remember, some of those edges are curves.

Redrobes
07-15-2009, 06:17 PM
Alfar - thats superb. I have never looked at this context free but it looks neat for what you did with it. Rep heading your way.

Toff - you must have read my mind too. If there is a way to generate a height map for those shapes using some blur etc then the thatching script would sound like a great tool to get oodles of thatched or tiled buildings.

waldronate
07-15-2009, 07:16 PM
A shapeburst or Distance Transform (same thing) should convert the basic mask to a heightfield as attached. Some of the ridgelines look a little peculiar with this method but it's fairly plausible overall.

Redrobes
07-15-2009, 07:22 PM
That looks cool - well done. I didnt know how to get to that without writing a program to do it. Shall I try it in the thatcher. Gimme a while and ill see what it makes of it. Its similar to the last time I tried this sort of thing...

Redrobes
07-15-2009, 07:49 PM
Actually this has worked extremely well (Edit -- darn it, it really has done well. That shape burst is the business !). If only we could solve placing these shapes into a city bounded by walls and roads...

Nice little collaboration going on here eh ?

Right so do you want tiles, slates, woodblock - we have it all baby !

töff
07-15-2009, 08:00 PM
Man, that's frikkin awesome. This guild rocks!

Redrobes
07-15-2009, 08:09 PM
A few more - if you need another tex then let me know.

RobA
07-15-2009, 08:10 PM
Redrobes-

If you can, apply the thatch texture without the lighting effect. That way if all the houses are dropped/rotated on the same transparent layer, you could just do a select by alpha and recreate the shapeburst then run your own light effect so the shadows all agree!

-Rob A>

Redrobes
07-15-2009, 08:19 PM
Ok, since I posted a few and what your asking is the advanced thing then here I have posted the "Anti Shadow" map (honest, its not all black). Add this to any of the images and it removes the lighting effect.

Heres my height map too incase you can register it with the other images and cut them out together of different layers to get at the shadows for them.

töff
07-15-2009, 08:37 PM
btw ... http://www.contextfreeart.org/gallery/view.php?id=185

waldronate
07-15-2009, 08:48 PM
The traditional solution for placement is to draw walls/roads/rivers into an occupied mask, then do a shapeburst (distance transform or DT) on the whitespace left over. The value of the DT is the distance from the occupied areas. The gradient of the DT is the angle at which the buildings should be placed to be parallel to the occupied areas. Place a set of buildings within some distance of the roads and render into the occupied mask. Apply additional rounds of building growth and masks to get the final result.

waldronate
07-15-2009, 08:59 PM
Context-free L-systems can give good results but they suffer from the fatal flaw that they write over themselves repeatedly. Context-sensitive L-systems have much the same problem. Environmentally-sensitive L-Systems, however, should be able to model street maps quite well. When I get through the 230 other things on my list I might get around to working on such as beast.

Redrobes
07-15-2009, 09:10 PM
Yeah, I kinda feel that you would need to put some humanity and irrational stuff in there to make it look like a city. Some rules about how to access the buildings, people taking shortest path and that kind of thing. I reckon it would be driven by economics to pack as many houses in with least amount of space wasted. Stuff like that. I have said a few times on here that it would be grand to have a program that did that on a huge scale for not just buildings but characters in the city and a full set of parameters driving how they act. It would be great to use that as a mechanism to drive what they do, where they go and ultimately where they build which would grind out cities with economic zones in them and feasible structure.

Alfar
07-16-2009, 12:22 AM
Actually... I'm already working on something... (http://www.cartographersguild.com/showthread.php?p=70018#post70018) :P

Edit: Also, I played around a bit more with Context Free, got this (attached) - sometimes the script spins itself into oblivion and you have to stop it, other times, it makes something that could at least somewhat look like a town - or cut in pieces and used for town creation.

Edit (2): I'm bored.

ravells
07-16-2009, 09:37 AM
I think RobA posted a link to a research paper on using L-systems for city modelling. It's a must read if you're thinking of coding something like this as it takes you through the main steps the researcher used to make his own L-system and there's lots of references to other works / research in the bibliography.

Alfar
07-16-2009, 09:56 AM
I'll be checking that out for sure. For the time being, I'm mostly concerned with drawing buildings based on a human-created layout, currently the streets I draw.

I just figured it was a way to pass a bit of time with Context Free, feeling quite done with that now ;)

ravells
07-26-2009, 12:54 PM
I've been playing around with Alfar's excellent context free building generator and it's exactly what I was looking for.

I've been trying to resist until my new computer arrives, but I gave in and had a play with it in photoshop.

Twinned with the lazy man's city style, or even just using the shapes by themselves with layerstyles, you should be able to put together a good looking town, villiage or city pretty quickly. As an extra bonus if you want more complex structure you can just overlap the buildings and they look like a single building.

Different layerstyles = different building materials / effects.

You just plonk the entire image created by context free into your map and then just drag and drop the buildings where you want them - easy (and great for a lazy mapper like me) each one looks individual. And if you want a slightly different style of building, you just adjust the code in context free.

Dragging and dropping is a bit fiddly in photoshop, so I might actually do that bit in vector and then import the result into photoshop - might be faster.

Can't wait to use this in anger when the new puter comes and I work towards completing Duerma's commission.

THANK YOU ALFAR!

Gandwarf
07-26-2009, 01:19 PM
That looks interesting Ravells. Some of the larger houses have a weird shape though.

ravells
07-26-2009, 01:26 PM
Yeah it definitely is for smaller buildings seen at a distance with lots of them. It wouldn't work if you wanted to do a large scale map of a villiage. It is possible to just draw the buildings within photoshop itself using squares and circles and let the layerstyles handle the bevelling and whatnot but I like having it done in advance and being able to pick and choose.

guyanonymous
07-26-2009, 06:16 PM
I hope you don't mind. I merged your cfdg file with the "bad urban planning" one (can't remember if it's part of Context Free or a freebie I downloaded for it somewhere) and came up with this...


startshape RURALTOWN

rule RURALTOWN {
STREET { }
STREET { rotate 89 }
STREET { rotate 180 }
}

rule STREET 2505 {
CIRCLE{ }
STREET { rotate 0.05 size 0.9995 y 0.1 }
}


rule STREET 2500 {
CIRCLE{ }
STREET { rotate -0.05 y 0.1 }
}

rule STREET 8 {
CIRCLE{ }
STREET { rotate -0.05 size 0.9995 y 0.1 }
Building { x 5}
}

rule STREET 6 {
CIRCLE{ }
STREET { rotate -0.05 y 0.1 }
Building { x -5 rotate 180 }
}

rule STREET 1 {
CIRCLE{ }
STREET { rotate 0.05 y 0.1 }
STREET { rotate 90.05 size 0.95 y 0.1 }
STREET { rotate -89 y 0.1 size 1.1 }
Building { x -5 rotate 180 }
}

rule STREET 1 {
CIRCLE{ }
STREET { rotate 0.05 y 0.1 }
STREET { rotate 90.05 size 0.98 y 0.1 }
Building { x 334 rotate 180 }
}

rule STREET 2 {
CIRCLE{ }
STREET { rotate 0.05 y 0.1 }
STREET { rotate -90.05 size 0.8 y 0.1 }

}

rule STREET 2 {
CIRCLE { }
}

rule BuildingPart {
SQUARE { s 2 4 }
}

rule BuildingPart {
SQUARE { s 3 4 }
}

rule BuildingPart 0.1 {
SQUARE { s 3 4 }
CIRCLE { y 2 s 3 3 }
}

rule BuildingPart 0.1 {
SQUARE { s 2 4 }
CIRCLE { y 2 s 2 2 }
}

rule ShortBuildingPart {
SQUARE { s 2 3 }
}

rule ShortBuildingPart {
SQUARE { s 3 3 }
}

rule ShortBuildingPart 0.1 {
SQUARE { s 3 3 }
CIRCLE { y 2 s 3 3 }
}

rule ShortBuildingPart 0.1 {
SQUARE { s 2 3 }
CIRCLE { y 2 s 2 2 }
}

rule ShortBuildingPart 0.1 {
SQUARE { s 2 3 }
CIRCLE { y 1.5 s 2 2 }
}

rule BuildingPart {
ShortBuildingPart { y -0.5 }
}

rule BuildingPart {
}


rule Building {
SQUARE { s 2 4 }
BuildingPart { x -1 y -2 r 90 }
BuildingPart { x -1 y 2 r 90 }
}

rule Building {
SQUARE { s 4 4 }
BuildingPart { x -2 r 90 }
BuildingPart { x 2 r 90 }
}


rule Building {
SQUARE { s 3 4 }
BuildingPart { x -0.5 y -2 r 90 }
BuildingPart { x -0.5 y 2 r 90 }
}

rule Building {
CIRCLE { s 4 4 }
BuildingPart { x -2 r 90 }
BuildingPart { x 2 r 90 }
BuildingPart { y -2 }
BuildingPart { y 2 }
}

rule Building {
Building { r 90 }
}

It's far from perfect (or even useable?), but it's been fun experimenting. I replaced the "BUILDING" rule calls with the "Building" ruile calls from the file here, and then multiplied scales by 10 in the fun builiding's code.

Just thought I'd share the results of a few minutes play.

ravells
07-26-2009, 06:21 PM
Interesting results! I'm sure with some work we could get Context free to deliver some even better results, even if they are just stepping stones to further work in other apps to finish them.

guyanonymous
07-26-2009, 06:27 PM
and oops...I'd not read past page 1...the streets and town uploads are next on the list to fdiddle with!

Thanks!

Alfar
07-27-2009, 07:37 AM
Not a problem. Good to see stuff I made being used for something useful for once ;)

guyanonymous - thanks for picking up the ball. I think I'm about done with Context Free for the time being, but it was a fun exercise. Looking forward to seeing what you can come up with.

BrockyL
09-23-2009, 06:48 PM
Dont suppose you guys have any advice on using these Lsystems with the gimp plugin eh?
Iwould love to start using these techniques myself, if you could share the versions of gimp that these were used with?

Alfar
09-24-2009, 02:21 AM
No experience with the gimp plugin. Context Free is a separate (free) piece of software that we used to do these thingies. It can output to png's, so it's pretty easy to move to gimp when you're about done with the generating bit.

zenram
09-24-2009, 10:57 AM
Well, a new piece of great software to add to the tools...

BrockyL
09-25-2009, 04:01 PM
By my Eye anyway It looks just like an Lsystem Ruleset. I cannot see how the buildings are being generated though, where they primitive's drawn by hand then made to order of bitmap fonts and used by grid. This is an excellent method if so I think Gimp has a Bitmap Character Set Creator. (ie. the character Map Flag in TTF Files.)