README

Noise::Simplex

Introduction

This is a naive implementation of 2D & 3D simplex noise in Raku.

It is not performant, but I believe it is correct.

Pull requests are welcome.

Usage

use Noise::Simplex;
use Image::PNG::Portable;

my $width = 512;
my $height = 512;
my $simplex = Simplex.new(seed => 12345);
my &noise2d = $simplex.create-noise2d;

my $img = Image::PNG::Portable.new: :$width, :$height, :alpha(False);

my @pixels;
for 0 ..^ $height -> $y {
    for 0 ..^ $width -> $x {
        my $n = noise2d($x / 64, $y / 64);
        my $val = ($n + 1) * 127.5;
        $img.set: $x, $y, $val.round, $val.round, $val.round;  # R, G, B grayscale
    }
}

$img.write: "img/2d.png";

See examples/3dnoise.raku for a 3D example.

Functions

Simplex.new

Takes a seed, returns a Simplex noise generator.

Simplex.create-noise2d

Creates a 2D noise map based on your seed, returns a sub that takes y to sample noise.

Simplex.create-noise3d

Creates a 3D noise map based on your seed, returns a sub that takes y, $z to sample noise.

Example Noise

2D Noise

image izef_noise_simplex_dist_img_2d_png not found

3D Noise

image izef_noise_simplex_dist_img_3d_png not found

Animated png made with ezgif.

Noise::Simplex v0.1.2

2D/3D Simplex noise generator

Authors

  • Matt Doughty

License

Artistic-2.0

Dependencies

Math::Random

Test Dependencies

Provides

  • Noise::Simplex

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.