diff --git a/examples/noise_simplex_2d/README.md b/examples/noise_simplex_2d/README.md new file mode 100644 index 000000000..dde860487 --- /dev/null +++ b/examples/noise_simplex_2d/README.md @@ -0,0 +1,16 @@ +# Example - plot_bar 📘 + +This example demonstrates the usage of the V Scientific Library for generating simplex noise. + +## Instructions + +1. Ensure you have the V compiler installed. You can download it from [here](https://vlang.io). +2. Ensure you have the VSL installed. You can do it following the [installation guide](https://github.com/vlang/vsl?tab=readme-ov-file#-installation)! +3. Navigate to this directory. +4. Run the example using the following command: + +```sh +v run main.v +``` + +Enjoy exploring the capabilities of the V Scientific Library! 😊 diff --git a/examples/noise_simplex_2d/main.v b/examples/noise_simplex_2d/main.v new file mode 100644 index 000000000..4a1985153 --- /dev/null +++ b/examples/noise_simplex_2d/main.v @@ -0,0 +1,38 @@ +module main + +import rand +import vsl.noise +import vsl.plot + +fn main() { + // Creation of the noise generator. + // Other noise functions and dimensions count are available. + rand.seed([u32(3155200429), u32(3208395956)]) + mut generator := noise.Generator.new() + generator.randomize() + + mut x := []f64{cap: 1600} + mut y := []f64{cap: 1600} + mut z := []f64{cap: 1600} + + for xx in 0 .. 40 { + for yy in 0 .. 40 { + // We need to scale the coordinates to control the frequency of the noise. + val := generator.simplex_2d(0.03 * xx, 0.03 * yy) + x << xx + y << yy + z << val + } + } + + mut plt := plot.Plot.new() + plt.heatmap( + x: x + y: y + z: z + ) + plt.layout( + title: 'Simplex noise 2d example' + ) + plt.show()! +}