Skip to content

Commit

Permalink
Zig implementation (#142)
Browse files Browse the repository at this point in the history
* [Zig] Added pure Zig implementation

* [Zig] Added README.md

* Updated README.md

Added Zig entry and updated contributor's section
  • Loading branch information
ForeverZer0 authored Oct 3, 2024
1 parent 72d212e commit 7fe9dca
Show file tree
Hide file tree
Showing 3 changed files with 2,016 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ If you are looking for a more extensive noise generation library consider using
- [Rust](/Rust/)
[![crates.io](https://img.shields.io/crates/v/fastnoise-lite?logo=rust "crates.io")](https://crates.io/crates/fastnoise-lite)
- [Fortran](/Fortran/)
- [Zig](/Zig/)

If you want to port FastNoise Lite to a new language create a pull request or discuss it on the discord linked above

Expand Down Expand Up @@ -86,7 +87,7 @@ Million points of noise generated per second (higher = better)
- [@Rover656](https://github.com/Rover656) for creating the preview GUI and porting FastNoise Lite to C and HLSL.
- [@snowfoxsh](https://github.com/snowfoxsh) for creating the JavaScript port.
- [@dotlogix](https://github.com/dotlogix) for creating the GLSL port.
- [@ForeverZer0](https://github.com/ForeverZer0) for creating the Go port.
- [@ForeverZer0](https://github.com/ForeverZer0) for creating the Zig and Go ports.
- [@Keavon](https://github.com/Keavon) for creating the Rust port.
- [@jordan4ibanez](https://github.com/jordan4ibanez) for creating the Fortran port.

Expand Down
33 changes: 33 additions & 0 deletions Zig/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Install

Simply copy the `fastnoise.zig` file directly into your project.

# Getting Started

The noise generator is implemented as a `comptime` function which returns a type, supporting both 32/64-bit floating-point types.
The generator does no allocations, nor is allocation required for initialization.

While the initial state of the generator is valid, you will likely want to pass in some configuration...
```zig
const fastnoise = @import("fastnoise.zig");
const noise = fastnoise.Noise(f32) {
.seed = 1337,
.noise_type = .cellular,
.frequency = 0.025,
.gain = 0.40,
.fractal_type = .fbm,
.lucunarity = 0.40,
.cellular_distance = .euclidian,
.cellular_return = .distance2,
.cellular_jitter_mod = 0.88,
};
const size = 128;
var values: [size * size]f32 = undefined;
for (0..values.len) |i| values[i] = noise.genNoise2D(@floatFromInt(i % size), @floatFromInt(i / size));
// Use noise values for whatever you please.
```

All functions of the generator are "pure" in that they do not alter its internal state, so you are free to initialize it as `const` if you will not be changing any of its fields afterwards.
Loading

0 comments on commit 7fe9dca

Please sign in to comment.