A role-playing game world map made with the Perlin Noise

A role-playing game world map made with the Perlin Noise.

 

It's an animation of a role-playing game world map made with the Perlin Noise.

It's a creative coding animation made with the 'Processing'. It draws an image that looks like a role-playing game world map.

Blog article about similar work in Japanese.

 

Using two Perlin Noise.

I used two Perlin Noise to draw this animation.
1. To draw a map.

noise(
      (width + nX + wander * cos(frmRatio * TWO_PI)) * nStep,
      (height + nY + wander * sin(frmRatio * TWO_PI)) * nStep
     );

↓...essentially a 2D noise.

noise(
      (width  + nX) * nStep,
      (height + nY) * nStep
     );

2. To wander around.
noise(
      wStep * (2.0 + cos(TWO_PI * frmRatio)),
      wStep * (2.0 + sin(TWO_PI * frmRatio))
     ) * width * 0.5;

It produces a cyclic noise value.
Reference : How to produce a cyclic noise value. (Japanese)







 

An example source code  of Processing.

This code does not display any images on the screen but generates image files in frames directory.
You can make an animation with these files.

Please feel free to use this example code under the terms of the GPL. To see other works based on my code is my pleasure. And my honor.


/**
 * Find Your Way Back.
 * explore the game world!
 * 
 * @author @deconbatch
 * @version 0.1
 * Processing 3.5.3
 * 2020.09.20
 */

void setup() {
  size(720, 640);
  colorMode(HSB, 360.0, 100.0, 100.0, 100.0);
  smooth();
  noLoop();
}

void draw() {

  int frmMax  = 24 * 12; // 24fps x 12sec
  int nodeMax = 3;
  int nodeDiv = 4;
  float nStep = 0.006; // noise pattern step
  float wStep = 0.5;   // wandering step

  translate(width * 0.5, height * 0.5);

  for (int frmCnt = 0; frmCnt < frmMax; frmCnt++) {

    float frmRatio = map(frmCnt, 0, frmMax, 0.0, 1.0);
    noStroke();

    // draw focusing to the center
    for (int i = 0; i <= 20; i++) {
      float ratio = map(i, 0, 20, 1.0, 0.0);
      fill(0, 0, 30 * ratio, 100);
      ellipse(0.0, 0.0, width * (0.5 + ratio), height * (0.5 + ratio));
    }

    // draw noise field
    for (float nX = -width * 0.5; nX <= width * 0.5; nX += nodeDiv * nodeMax) {
      for (float nY = -height * 0.5; nY <= height * 0.5; nY += nodeDiv * nodeMax) {
        float x = nX;
        float y = nY;
        for (int nodeCnt = 0; nodeCnt < nodeMax; nodeCnt++) {
          // wandering about
          float wander = noise(
                              wStep * (2.0 + cos(TWO_PI * frmRatio)),
                              wStep * (2.0 + sin(TWO_PI * frmRatio))
                               ) * width * 0.5;
          // noise pattern + wandering
          float nVal = noise(
                             (width + nX + wander * cos(frmRatio * TWO_PI)) * nStep,
                             (height + nY + wander * sin(frmRatio * TWO_PI)) * nStep
                             );
          // limit 8 directions
          float theta = floor(16.0 * nVal) * TWO_PI / 8.0;
          theta %= TWO_PI;
          x += nodeDiv * cos(theta);
          y += nodeDiv * sin(theta);
          fill((theta / TWO_PI) * 360.0, 90.0, 80.0, 100.0);
          ellipse(x, y, nodeDiv, nodeDiv);
        }
      }
    }
    
    saveFrame("frames/" + String.format("%04d", frmCnt) + ".png");

  }
  exit();
}


/*
Copyright (C) 2020- deconbatch

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
*/



 

Next Post Previous Post
No Comment
Add Comment
comment url