Links

Categories

Tags


« | Main | »

Render Island Effect (Heightmap)

By Jewe | July 1, 2014

Renders a heightmap for an island that can be imported in tools like WorldPainter to create a MineCraft map. (IrfanView Sandbox 1.2)

Download this script

import Random;
import Math;
import RasterizerSSE;

using Math;

class RenderIsland : Effect
{
    Slider XSeed, XFreq, YSeed, YFreq, SPers, SOcts, SInt1, SInt2, SInt3, SInt4;
    Label L1, L2, L3, L4;

    PerlinNoise Perlin;
    float SeedX, SeedY;
    float Freq1, Freq2;
    float Int1, Int2;
    float MaxX, MaxY;
    float Int3, Baseh;

    method RenderIsland()
    {
        Perlin = null;
        SeedX = 0;
        SeedY = 0;
        Freq1 = 0;
        Freq2 = 0;
        Int1 = 0;
        Int2 = 0;
        MaxX = 0;
        MaxY = 0;
        Int3 = 0;
        Baseh = 0;

        L1     = new Label("Start Position");
        XSeed  = new Slider("X Seed", "", 0, 0, 255, 2);
        YSeed  = new Slider("Y Seed", "", 0, 0, 255, 71);
        L2     = new Label("Landscape Features");
        XFreq  = new Slider("Mountain Scale", "", 1, 1, 10, 4);
        SInt1  = new Slider("Mountain Height", "", 2, 0, 1, 0.5);
        YFreq  = new Slider("Bump Scale", "", 1, 1, 10, 10);
        SInt2  = new Slider("Bump Height", "", 2, 0, 0.3, 0.2);
        L3     = new Label("Island Shape");
        SInt3  = new Slider("Flatness / Steepness", "", 2, 0, 1, 0.65);
        SInt4  = new Slider("Base Height", "", 0, 0, 255, 44);
        L4     = new Label("Random Properties");
        SPers  = new Slider("Smoothing", "", 2, 0, 1, 0.6);
        SOcts  = new Slider("Level of Detail", "", 0, 1, 10, 5);
    }

    method Parameter[] GetParameters()
    {
        return {
            L1, XSeed, YSeed,
            L2, XFreq, SInt1, YFreq, SInt2,
            L3, SInt3, SInt4,
            L4, SPers, SOcts
        };
    }

    method EffectInfo GetEffectInfo()
    {
        return new EffectInfo(
            "Render Island",
            "by Jewe",
            "Renders the height map of an island."
        );
    }

    method DoEffect(Image img)
    {
        // create rasterizer for the image
        RasterizerSSE land = new RasterizerSSE(img);
        // set up Perlin noise
        Perlin = new PerlinNoise(SOcts.Value, SPers.Value);
        SeedX = XSeed.Value;
        SeedY = YSeed.Value;
        float zoom = 512.0 / img.Rectangle.Height;
        Freq1 = 0.002 * XFreq.Value * zoom;
        Freq2 = 0.022 * YFreq.Value * zoom;
        Int1 = SInt1.Value;
        Int2 = SInt2.Value * 0.03;
        Int3 = SInt3.Value * 0.5;
        Baseh = SInt4.Value / 256.0;
        MaxX = Math::PI / img.Rectangle.Width;
        MaxY = Math::PI / img.Rectangle.Height;
        // render map
        land.ProcessPixels(RenderHeightMap);
        // finalize
        land.Finalize();
    }

    method RenderHeightMap(const int x, const int y, ColorRGB c)
    {
        float s = Pow(Perlin.Random(SeedX + x * Freq1, SeedY + y * Freq1) * Int1, 3.0);
        float t = Perlin.Random(SeedX + x * Freq2, SeedY + y * Freq2) * Int2;
        float u = Sin(x * MaxX) * Sin(y * MaxY) * Int3;
        c.Set(s + t + u + Baseh);
    }
}

Topics: code examples, filter sandbox | Comments Off on Render Island Effect (Heightmap)

Comments are closed.