PDA

View Full Version : GIMP script: Random cave generator



isomage
12-09-2008, 03:41 AM
Here's a random cave generator I just wrote with GIMP's script-fu; it's basically a reimplementation of my online cave generator, except instead of using the old-school TSR blue style with a grid, this was designed to be used with RobA's subterranean map prettier script (http://www.cartographersguild.com/showthread.php?t=2759).

This is only my second attempt at GIMP scripting, and it's only the first draft, so no doubt I've done something stupid somewhere; advice from more experienced scripters is welcome (is there really no floating-point random number generator? No pi?).

I've attached a map made with my script, followed by the result of scaling it by 200% and applying RobA's script (grid size 15, all other parameters default).

Installation and use:

Once you've installed the .scm file in your gimp scripts directory, it's accessible under Xtns / Script-Fu / Utils (if there's a more appropriate place to put it let me know, and let me know how).

Parameters: image size (the dimensions of the image in pixels), number of random walks (the caves are excavated by drunken dwarves), and length of the walks. Default values should work well enough.

The code is free -- do with it what you will.

I hope you enjoy it, and feedback is always welcome.

Updated: Version 0.3.1 - fixed error with grid toggle

isomage
12-09-2008, 06:55 AM
And the first problem appears: it seems to generate the same sequence of caves each time. How does one seed the random number generator randomly in GIMP?

Edit: Fixed.

Sagenlicht
12-09-2008, 08:40 AM
Hmm sry isomage, I've got some troubles reading script-fu, which makes troubleshooting tough for me. If you give me a python code I'll help ya.

isomage
12-09-2008, 08:49 PM
Here's another example, this from version 0.1.2 (with improved path rendering to reduce square features), again rendered with RobA's script.

RobA
12-10-2008, 12:29 AM
yummy.

I will have to take a look at your code!

-Rob A>

Steel General
12-10-2008, 07:22 AM
Cool stuff Isomage!

Ascension
12-10-2008, 07:01 PM
Makes me want to learn how to GIMP.

RobA
12-10-2008, 09:19 PM
Well, your scheme coding skills are waaay better than mine... I'm assuming you actually know scheme!

The only thing I don't get is what this bit a the end is for:


; Magic!

(gimp-invert layer)
(plug-in-sobel RUN-NONINTERACTIVE image layer 1 1 1)
(gimp-invert layer)
(let ((select-point (screen-coordinates '(0 0))))
(gimp-fuzzy-select layer
(car select-point) (cadr select-point)
1 CHANNEL-OP-ADD TRUE FALSE 0 FALSE))
(gimp-selection-invert image)
(gimp-edit-bucket-fill layer FG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
(gimp-selection-none image)


I think the same could be done with a simple erode and invert.

One other suggestion would be to have the user specify the brush size rather than using the 12 px brush.... You'd also have to space the random walk step size proportionately, of course.

The code to programmaticly define a hard edged brush is:


;Set up Brush
(set! brushTemp (car (gimp-brush-new "MyBrush")))
(gimp-brush-set-shape brushTemp BRUSH-GENERATED-CIRCLE)
(gimp-brush-set-hardness brushTemp 1)
(gimp-brush-set-radius brushTemp varRadius)
(gimp-brush-set-spacing brushTemp varSpacing)
(gimp-brush-set-spikes brushTemp 2)
(gimp-brush-set-aspect-ratio brushTemp 1)
(gimp-brush-set-angle brushTemp 0)
(gimp-context-set-brush brushTemp)


and then destroy after use by:


(gimp-brush-delete brushTemp)


(Of course this would also let you vary the brush size in a random walk itself! just call the gimp-brush-set-radius whenever)

-Rob A>

isomage
12-10-2008, 10:45 PM
I'm assuming you actually know scheme!

I like Lisp, and Scheme's just a dialect -- they have a lot in common.


The only thing I don't get is what this bit a the end is for:
...
I think the same could be done with a simple erode and invert.

Ah, you're right -- that stuff follows the process I used to use when I first started playing with this sort of thing, and it's basically redundant now. I've replaced it with an erode. Thanks :)


One other suggestion would be to have the user specify the brush size

I've been thinking about that; it'll probably make it into a future version.


Of course this would also let you vary the brush size in a random walk itself!

That's definitely worth investigating.

Thanks for the advice; I've updated the zip file in the first post to remove that redundant code.

isomage
12-11-2008, 07:16 AM
Added color, brush sizing, optional grid. Default settings will still work as input for RobA's script, but it can now make blue, gridded TSR-style maps as well.

isomage
12-11-2008, 04:03 PM
Fixed a bug with the grid toggle.

NymTevlyn
02-22-2009, 06:20 PM
Can this make images with the grid at 50px per square?

RobA
02-22-2009, 09:24 PM
I just tried it. Yes.

-Rob A>