Miscellaneous Procedural Generation Code

About Monkey 2 Forums Monkey 2 Projects Miscellaneous Procedural Generation Code

This topic contains 18 replies, has 5 voices, and was last updated by  codifies 2 years, 2 months ago.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #6743

    impixi
    Participant

    Perlin noise

    (See attachment for runnable example)

    [/crayon]
    Attachments:
    1. perlin.monkey2.zip
    #6745

    impixi
    Participant

    Hill algorithm:

    (See attachment for runnable example)

    [/crayon]
    #6746

    impixi
    Participant

    Midpoint Displacement

    (See attachment for runnable example)

    [/crayon]
    Attachments:
    1. mpd.monkey2.zip
    #6747

    Pakz
    Participant

    Any chance of a short description on how they work? (Couple of lines maybe?)

    My current method for making heightmaps is like this :

    Draw randomly sized rectangles on top of each other. When drawn ontop add the value together. At a certain high value stop the procedure and you are done.

    The result looks pretty much like a heightmap. Is pretty easy to code too.

    #6749

    codifies
    Participant

    very nice, I especially like the hill method, but notice sometimes a definite plus sign shape in them sometimes.

    I assume you realise that seeding with millisecs will often have almost identical results (its millisecs from app start)

    but nice work.

    #6751

    impixi
    Participant

    @pakz

    Here are some links that explain, in depth, the algorithms that the above code is inspired/based on:

    Perlin
    http://devmag.org.za/2009/04/25/perlin-noise/

    Hill algorithm.
    http://www.stuffwithstuff.com/robot-frog/3d/hills/hill.html

    Midpoint displacement (aka Diamond Square algorithm)
    https://en.wikipedia.org/wiki/Diamond-square_algorithm

    Your technique sounds similar to the “hill algorithm”, except you use rectangles instead of circles/ovals. I’d be interested in seeing your code!

    #6752

    impixi
    Participant

    @codifies

    Yes, if you seed the RNG with the same number you should see the same results regardless of platform, since Monkey 2’s RNG algorithm is platform agnostic.

    EDIT. Sorry, I misunderstood your statement. Yes, I realise Millisecs and Microsecs are derived from the application start time so the results are likely to be the same…

    #6753

    codifies
    Participant

    don’t suppose you can improve on this?

    [/crayon]
    #6756

    cocon
    Participant

    This looks good.

    #6763

    impixi
    Participant

    @codifies

    That’s good enough, no improvement necessary.

    For simple proof of concept code I usually don’t bother seeding with a unique number per run but I should. So I’m going to incorporate your code snippet, though slightly simplified. 🙂

    Another way to do it, if you’re not generating something right at the start, is to seed with Microsecs at the point of first user interaction. That’s what I do for my game projects and simulations.

    #6767

    impixi
    Participant

    Particle deposition:

    (See attachment for runnable example)

    [/crayon]
    #6769

    impixi
    Participant

    Fault Algorithm:

    (See attachment for runnable example)

    [/crayon]
    Attachments:
    1. fault.monkey2.zip
    #6770

    impixi
    Participant

    Relevant theory links for the previous two examples…

    Particle Deposition:
    Generating heightmaps using particle deposition

    Fault Algorithm:
    http://www.lighthouse3d.com/opengl/terrain/index.php?fault

    #6772

    nerobot
    Participant

    Very nice! 🙂

    One note: looking at these walls of code I have a question – is there way to make code box smaller? And I looked into “code” popup and found “Height” checkbox, that disabled by default.

    I didn’t try it yet but it seems to be useful for big code blocks.

    #6788

    impixi
    Participant

    @nerobot

    I can’t find a way to do it so I’m going to paste only the pertinent function(s) in each post body and “attach” the complete runnable example as a zip file…

    EDIT: Still a “wall of code” but not quite as bad. 😉

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic.