### Generate 2D Noise with Go Source: https://github.com/keinos/go-noise/blob/main/_example/README.md Example demonstrating the generation of 2D noise. This code is typically run from the command line within the specified example directory. No specific dependencies beyond the go-noise library are mentioned. ```bash cd ./_example/2d && go run . ``` -------------------------------- ### Generate 3D Noise with Go Source: https://github.com/keinos/go-noise/blob/main/_example/README.md Example showing 3D noise generation, potentially using time as the third dimension. Execution involves navigating to the example directory and running the Go program. It relies on the go-noise library. ```bash cd ./_example/3d && go run . ``` -------------------------------- ### Install Go-Noise Module (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Provides the command to add the go-noise package as a dependency to your Go project using the go get command. This is the first step before importing and using the package in your code. ```go go get "github.com/KEINOS/go-noise" // import "github.com/KEINOS/go-noise" ``` -------------------------------- ### Configure Perlin Noise Smoothness and Scale in Go Source: https://github.com/keinos/go-noise/blob/main/_example/README.md Illustrates how to customize the Perlin noise algorithm by adjusting alpha (smoothness) and beta (scale) values. The code shows how to initialize Perlin noise and then modify its Smoothness and Scale fields. It requires the go-noise library. ```go alpha := 1.5 beta := 1.5 n, err := noise.New(noise.Perlin, seed) n.Smoothness = alpha n.Scale = beta ``` -------------------------------- ### 1D Noise Example Usage (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Demonstrates how to generate a 1D noise value and scale it to a specific range. This example uses `noise.Perlin` and scales the output from [-1, 1] to [0, 500]. It highlights the use of `Eval64` and subsequent re-mapping. ```go import "github.com/KEINOS/go-noise" const seed = 100 // noise pattern ID const smoothness = 100 // noise smoothness // noiseType choises // noise.Perlin // noise.OpenSimplex // noise.Custom n, err := noise.New(noise.Perlin, seed) // Assuming x is defined elsewhere // yy := n.Eval64(x / smoothness) // yy is between -1.0 and 1.0 of float64 // y := (yy + 1) / 2 * 500 // y is between 0 and 500 ``` -------------------------------- ### 2D Noise Example Usage (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Illustrates obtaining a 2D noise value at a specific coordinate (x, y). This value can then be used to construct 2D images by mapping the noise output to pixel colors or other visual properties. The example uses a generic `noiseType` and `seed`. ```go // Obtain the noise value at the position (x, y) // n, err := noise.New(noiseType, seed) // v := n.Eval64(x, y) // v is between -1.0 and 1.0 of float64 ``` -------------------------------- ### Generate 2D Noise for Heightmaps with Go-Noise Source: https://context7.com/keinos/go-noise/llms.txt Illustrates generating 2D noise using `Generator.Eval64()` for creating heightmaps. The example normalizes coordinates, generates noise values, and converts them into grayscale pixel data to save as a PNG image. This is applicable for procedural terrain and texture generation. ```go package main import ( "fmt" "image" "image/color" "image/png" "log" "os" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 const width, height = 256, 256 const scale = 50.0 gen, err := noise.New(noise.OpenSimplex, seed) if err != nil { log.Fatal(err) } // Create heightmap image img := image.NewGray(image.Rect(0, 0, width, height)) for y := 0; y < height; y++ { for x := 0; x < width; x++ { // Normalize coordinates xx := float64(x) / scale yy := float64(y) / scale // Get noise value [-1, 1] noiseValue := gen.Eval64(xx, yy) // Convert to grayscale [0, 255] grayValue := uint8((noiseValue + 1) / 2 * 255) img.SetGray(x, y, color.Gray{Y: grayValue}) } } // Save to file file, err := os.Create("heightmap.png") if err != nil { log.Fatal(err) } defer file.Close() if err := png.Encode(file, img); err != nil { log.Fatal(err) } fmt.Println("2D heightmap saved to heightmap.png") } ``` -------------------------------- ### Go Batch Noise Generation for Performance Source: https://context7.com/keinos/go-noise/llms.txt This Go program demonstrates how to efficiently generate a large grid of noise values for performance. It uses the go-noise library, pre-allocates memory for the noise grid, and measures the time taken for generation and statistics calculation. The output includes the number of values generated, time elapsed, and performance in values per second. ```go package main import ( "fmt" "log" "time" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 const gridSize = 1000 gen, err := noise.New(noise.OpenSimplex, seed) if err != nil { log.Fatal(err) } // Pre-allocate slice for performance heightmap := make([][]float64, gridSize) for i := range heightmap { heightmap[i] = make([]float64, gridSize) } start := time.Now() // Generate noise values scale := 50.0 for y := 0; y < gridSize; y++ { yy := float64(y) / scale for x := 0; x < gridSize; x++ { xx := float64(x) / scale heightmap[y][x] = gen.Eval64(xx, yy) } } elapsed := time.Since(start) // Calculate statistics var min, max, sum float64 min = heightmap[0][0] max = heightmap[0][0] for y := 0; y < gridSize; y++ { for x := 0; x < gridSize; x++ { val := heightmap[y][x] sum += val if val < min { min = val } if val > max { max = val } } } count := gridSize * gridSize avg := sum / float64(count) fmt.Printf("Generated %d noise values in %v\n", count, elapsed) fmt.Printf("Min: %.4f, Max: %.4f, Avg: %.4f\n", min, max, avg) fmt.Printf("Performance: %.0f values/second\n", float64(count)/elapsed.Seconds()) } ``` -------------------------------- ### Compare Perlin and OpenSimplex Noise Algorithms (Go) Source: https://context7.com/keinos/go-noise/llms.txt This Go code compares the output of Perlin and OpenSimplex noise algorithms for the same input coordinates. It initializes both noise generators with the same seed and then prints the noise values for 1D and 2D coordinates. This helps visualize the differences in their noise patterns. The `noise` package is required. ```go package main import ( "fmt" "log" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 // Create both generators with same seed perlinGen, err := noise.New(noise.Perlin, seed) if err != nil { log.Fatal(err) } simplexGen, err := noise.New(noise.OpenSimplex, seed) if err != nil { log.Fatal(err) } fmt.Println("Comparing noise algorithms at various coordinates:") fmt.Println("Coord\t\tPerlin\t\tOpenSimplex") // Compare 1D noise for x := float64(0); x <= 2; x++ { perlin := perlinGen.Eval64(x / 10) simplex := simplexGen.Eval64(x / 10) fmt.Printf("(%.1f)\t\t%.4f\t\t%.4f\n", x, perlin, simplex) } fmt.Println("\n2D Coordinates:") // Compare 2D noise for x := float64(0); x < 2; x++ { for y := float64(0); y < 2; y++ { perlin := perlinGen.Eval64(x/10, y/10) simplex := simplexGen.Eval64(x/10, y/10) fmt.Printf("(%.0f,%.0f)\t\t%.4f\t\t%.4f\n", x, y, perlin, simplex) } } // Note: OpenSimplex typically has fewer directional artifacts // than Perlin noise, especially noticeable in 2D/3D } ``` -------------------------------- ### Create Noise Generator with Go-Noise Source: https://context7.com/keinos/go-noise/llms.txt Demonstrates how to create new noise generators using the `noise.New()` function. It supports Perlin, OpenSimplex, and custom noise types, each requiring a seed for reproducible results. Error handling is included for generator creation. ```go package main import ( "fmt" "log" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 // Create Perlin noise generator perlinGen, err := noise.New(noise.Perlin, seed) if err != nil { log.Fatal(err) } // Create OpenSimplex noise generator simplexGen, err := noise.New(noise.OpenSimplex, seed) if err != nil { log.Fatal(err) } // Create custom noise generator customGen, err := noise.New(noise.Custom, seed) if err != nil { log.Fatal(err) } fmt.Printf("Perlin generator created: %v\n", perlinGen != nil) fmt.Printf("OpenSimplex generator created: %v\n", simplexGen != nil) fmt.Printf("Custom generator created: %v\n", customGen != nil) } ``` -------------------------------- ### Initialize Noise Generator (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Creates a new noise generator with a specified algorithm and seed. Supports Perlin, OpenSimplex, and custom noise algorithms. The seed determines the noise pattern, and the same seed will produce identical noise patterns. An error is returned if initialization fails. ```go const seed = 100 // Noise generator for Perlin noise genNoise, err := noise.New(noise.Perlin, seed) ``` ```go const seed = 100 // Noise generator for OpenSimplex noise genNoise, err := noise.New(noise.OpenSimplex, seed) ``` ```go const seed = 100 // Noise generator for Custom noise genNoise, err := noise.New(noise.Custom, seed) // User defined noise generator myNoise32 := func(seed int64, dim ...float32) float32 { // ... } // Assign generator for float32 type genNoise, err := genNoise.SetEval32(myNoise32) ``` -------------------------------- ### Generate 1D Noise Values with Go-Noise Source: https://context7.com/keinos/go-noise/llms.txt Shows how to use the `Generator.Eval64()` method to generate 1D noise values. This is useful for creating smooth, continuous data along a single axis. The output noise values are between -1 and 1 and can be scaled for specific applications. ```go package main import ( "fmt" "log" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 const smoothness = 100.0 gen, err := noise.New(noise.Perlin, seed) if err != nil { log.Fatal(err) } // Generate noise values along a line for x := 0; x < 10; x++ { xx := float64(x) / smoothness noiseValue := gen.Eval64(xx) // Scale from [-1, 1] to [0, 500] scaledValue := (noiseValue + 1) / 2 * 500 fmt.Printf("x=%d, noise=%.4f, scaled=%.2f\n", x, noiseValue, scaledValue) } // Output shows smooth transitions between values } ``` -------------------------------- ### Generate Perlin Noise for 3D Animation in Go Source: https://github.com/keinos/go-noise/blob/main/README.md This Go code snippet demonstrates how to generate Perlin noise and use it to create frames for a 3D animation. It initializes a Perlin noise generator, iterates through frames and pixels, calculates noise values, scales them to grayscale, and prepares them for plotting. Error handling for generator creation is included. Dependencies include the 'github.com/KEINOS/go-noise' package and 'image/color'. ```go import ( "github.com/KEINOS/go-noise" "image/color" ) const seed = 100 const frame = 50 // Assuming width, height are defined elsewhere // var width int // var height int func generateNoiseAnimation() { // Create new noise generator of Perlin type genNoise, err := noise.New(noise.Perlin, seed) if err != nil { // error handle panic(err) } for z := 0; z < frame; z++ { zz := float64(z) / 5 // smoothness between frames /* Here create a new image of a frame */ for y := 0; y < height; y++ { yy := float64(y) / 25 // smoothness between plotting points for x := 0; x < width; x++ { xx := float64(x) / 25 // smoothness between plotting points // n is a float64 value between -1 and 1 n := genNoise.Eval64(xx, yy, zz) // Convert n to 0-255 scale // Note: Original code had 'in' instead of 'n', assuming 'n' was intended. grayColor := ((1. - n) / 2.) * 255. pixelToPlot := color.Gray{Y: uint8(grayColor)} /* Here plot the pixel to the current image */ } } /* Here save the current frame/image to a file */ } /* Here animate the frames if you want */ } ``` -------------------------------- ### Generate Terrain Map with Octaves (Go) Source: https://context7.com/keinos/go-noise/llms.txt This Go program demonstrates practical terrain generation using the Perlin noise algorithm with multiple octaves for enhanced realism. It creates a 512x512 image where pixel colors are determined by the calculated elevation, ranging from water to snow. The generated terrain map is saved as 'terrain.png'. It requires the standard Go image and PNG packages, along with the `go-noise` library. ```go package main import ( "fmt" "image" "image/color" "image/png" "log" "math" "os" "github.com/KEINOS/go-noise" ) func main() { const seed = 12345 const width, height = 512, 512 gen, err := noise.New(noise.Perlin, seed) if err != nil { log.Fatal(err) } img := image.NewRGBA(image.Rect(0, 0, width, height)) // Terrain generation with multiple octaves for y := 0; y < height; y++ { for x := 0; x < width; x++ { // Sample at multiple frequencies (octaves) elevation := 0.0 amplitude := 1.0 frequency := 1.0 maxValue := 0.0 for octave := 0; octave < 5; octave++ { xx := float64(x) / 100.0 * frequency yy := float64(y) / 100.0 * frequency noiseVal := gen.Eval64(xx, yy) elevation += noiseVal * amplitude maxValue += amplitude amplitude *= 0.5 // Each octave contributes less frequency *= 2.0 // Each octave has higher frequency } // Normalize to [0, 1] elevation = (elevation / maxValue + 1) / 2 // Apply terrain coloring var c color.RGBA switch { case elevation < 0.3: // Water (blue) c = color.RGBA{30, 100, 200, 255} case elevation < 0.4: // Beach (yellow) c = color.RGBA{238, 214, 175, 255} case elevation < 0.6: // Grass (green) green := uint8(elevation * 400) c = color.RGBA{34, green, 34, 255} case elevation < 0.8: // Mountain (gray) gray := uint8(elevation * 255) c = color.RGBA{gray, gray, gray, 255} default: // Snow (white) c = color.RGBA{255, 255, 255, 255} } img.Set(x, y, c) } } file, err := os.Create("terrain.png") if err != nil { log.Fatal(err) } defer file.Close() if err := png.Encode(file, img); err != nil { log.Fatal(err) } fmt.Println("Terrain map generated: terrain.png") } ``` -------------------------------- ### noise.New() - Create Noise Generator Source: https://context7.com/keinos/go-noise/llms.txt Creates a new noise generator with the specified algorithm type and seed value. Supports Perlin, OpenSimplex, and custom noise algorithms. ```APIDOC ## noise.New() ### Description Creates a new noise generator with the specified algorithm type and seed value. ### Method `noise.New(algorithmType, seed)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "fmt" "log" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 // Create Perlin noise generator perlinGen, err := noise.New(noise.Perlin, seed) if err != nil { log.Fatal(err) } // Create OpenSimplex noise generator simplexGen, err := noise.New(noise.OpenSimplex, seed) if err != nil { log.Fatal(err) } // Create custom noise generator customGen, err := noise.New(noise.Custom, seed) if err != nil { log.Fatal(err) } fmt.Printf("Perlin generator created: %v\n", perlinGen != nil) fmt.Printf("OpenSimplex generator created: %v\n", simplexGen != nil) fmt.Printf("Custom generator created: %v\n", customGen != nil) } ``` ### Response #### Success Response (200) - **noise.Generator** (*interface{}*) - A noise generator instance. - **error** (*error*) - An error if the generator creation fails. #### Response Example ```json { "generator": "", "error": null } ``` ``` -------------------------------- ### Generator.SetEval32() and SetEval64() - Custom Noise Functions Source: https://context7.com/keinos/go-noise/llms.txt Allows you to define and set custom noise generation functions, enabling specialized algorithms or the use of custom pseudo-random patterns. ```APIDOC ## Generator.SetEval32() and Generator.SetEval64() ### Description Define custom noise generation functions for specialized algorithms or pseudo-random patterns. These methods allow you to inject your own noise generation logic into the generator. ### Method N/A (These are methods of a Generator object, not direct API endpoints) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go // Example usage within a Go program: // Define custom float32 noise function customNoise32 := func(seed int64, dim ...float32) float32 { // ... custom logic ... return v*2 - 1 } gen.SetEval32(customNoise32) // Define custom float64 noise function customNoise64 := func(seed int64, dim ...float64) float64 { // ... custom logic ... return v*2 - 1 } gen.SetEval64(customNoise64) ``` ### Response #### Success Response (200) N/A (These are method calls, not HTTP responses) #### Response Example ```go // After setting a custom function, Eval32 or Eval64 will use that function. result := gen.Eval32(1, 2, 3) result64 := gen.Eval64(5.5, 10.2) ``` ``` -------------------------------- ### Set Custom Noise Functions with SetEval32() and SetEval64() in Go Source: https://context7.com/keinos/go-noise/llms.txt Allows defining and assigning custom noise generation functions for float32 and float64 outputs. This is useful for implementing specialized algorithms or custom pseudo-random patterns. ```Go package main import ( "fmt" "log" "math/rand" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 // Create custom noise generator gen, err := noise.New(noise.Custom, seed) if err != nil { log.Fatal(err) } // Define custom float32 noise function var rnd *rand.Rand customNoise32 := func(seed int64, dim ...float32) float32 { if rnd == nil { rnd = rand.New(rand.NewSource(seed)) } // Iterate based on dimensions for i := 0; i < len(dim); i++ { max := int(dim[i]) for j := 0; j < max; j++ { _ = rnd.Float32() } } // Generate pseudo-random value v := rnd.Float32() return v*2 - 1 // Scale [0,1] to [-1,1] } // Assign custom function if err := gen.SetEval32(customNoise32); err != nil { log.Fatal(err) } // Use custom noise generator result := gen.Eval32(1, 2, 3) fmt.Printf("Custom noise at (1,2,3): %.7f\n", result) // Define custom float64 noise function customNoise64 := func(seed int64, dim ...float64) float64 { source := rand.NewSource(seed) rng := rand.New(source) // Simple hash-based noise hash := seed for _, d := range dim { hash ^= int64(d * 1000) } rng.Seed(hash) v := rng.Float64() return v*2 - 1 } if err := gen.SetEval64(customNoise64); err != nil { log.Fatal(err) } result64 := gen.Eval64(5.5, 10.2) fmt.Printf("Custom noise64 at (5.5, 10.2): %.7f\n", result64) } ``` -------------------------------- ### Generate Noise with Generator.Eval32() in Go Source: https://context7.com/keinos/go-noise/llms.txt Generates float32 noise values, optimized for memory efficiency or GPU computations. Supports 1D, 2D, and 3D noise generation using the OpenSimplex algorithm. ```Go package main import ( "fmt" "log" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 gen, err := noise.New(noise.OpenSimplex, seed) if err != nil { log.Fatal(err) } // 1D noise with float32 for x := float32(0); x < 5; x++ { noise1D := gen.Eval32(x / 10) fmt.Printf("1D: x=%.1f, noise=%.4f\n", x, noise1D) } // 2D noise with float32 for x := float32(0); x < 3; x++ { for y := float32(0); y < 3; y++ { noise2D := gen.Eval32(x/10, y/10) fmt.Printf("2D: (%.1f, %.1f) = %.4f\n", x, y, noise2D) } } // 3D noise with float32 noise3D := gen.Eval32(1.0, 2.0, 3.0) fmt.Printf("3D: (1.0, 2.0, 3.0) = %.4f\n", noise3D) } ``` -------------------------------- ### 3D OpenSimplex Noise Generation (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Demonstrates generating a 3D noise value using the OpenSimplex algorithm at coordinates (x, y, z). Similar to Perlin noise, the 'z' axis can be used for animation frames. The resulting noise value 'v' is a float64 within the [-1.0, 1.0] range. ```go // Obtain the noise value at the position (x, y, z) // n, err := noise.New(noise.OpenSimplex, seed) // v := n.Eval64(x, y, z) // v is between -1.0 and 1.0 of float64 ``` -------------------------------- ### Generate 3D Noise with Generator.Eval64() in Go Source: https://context7.com/keinos/go-noise/llms.txt Generates float64 noise values for 3D coordinates, suitable for animated textures and volumetric effects. It utilizes the Perlin noise algorithm and outputs an animated GIF. ```Go package main import ( "fmt" "image" "image/color" "image/gif" "log" "os" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 const width, height = 200, 200 const frames = 30 const scale = 25.0 gen, err := noise.New(noise.Perlin, seed) if err != nil { log.Fatal(err) } var images []*image.Paletted var delays []int // Generate animated frames for z := 0; z < frames; z++ { zz := float64(z) / 5.0 // Time axis smoothness img := image.NewPaletted( image.Rect(0, 0, width, height), getPalette(), ) for y := 0; y < height; y++ { yy := float64(y) / scale for x := 0; x < width; x++ { xx := float64(x) / scale // Get 3D noise value noiseValue := gen.Eval64(xx, yy, zz) // Convert to color index colorIndex := uint8((noiseValue + 1) / 2 * 255) img.SetColorIndex(x, y, colorIndex) } } images = append(images, img) delays = append(delays, 5) // 50ms per frame } // Save animated GIF file, err := os.Create("animation.gif") if err != nil { log.Fatal(err) } defer file.Close() if err := gif.EncodeAll(file, &gif.GIF{ Image: images, Delay: delays, }); err != nil { log.Fatal(err) } fmt.Printf("3D animated noise saved with %d frames\n", frames) } func getPalette() color.Palette { palette := make(color.Palette, 256) for i := 0; i < 256; i++ { palette[i] = color.Gray{Y: uint8(i)} } return palette } ``` -------------------------------- ### Generator.Eval64() - Generate 1D Noise Source: https://context7.com/keinos/go-noise/llms.txt Generates a float64 noise value for a single coordinate. Useful for one-dimensional procedural generation like generating data along a line. ```APIDOC ## Generator.Eval64(x float64) ### Description Generates a float64 noise value for a single coordinate, useful for one-dimensional procedural generation. ### Method `generator.Eval64(x float64)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "fmt" "log" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 const smoothness = 100.0 gen, err := noise.New(noise.Perlin, seed) if err != nil { log.Fatal(err) } // Generate noise values along a line for x := 0; x < 10; x++ { xx := float64(x) / smoothness noiseValue := gen.Eval64(xx) // Scale from [-1, 1] to [0, 500] scaledValue := (noiseValue + 1) / 2 * 500 fmt.Printf("x=%d, noise=%.4f, scaled=%.2f\n", x, noiseValue, scaledValue) } // Output shows smooth transitions between values } ``` ### Response #### Success Response (200) - **noiseValue** (*float64*) - A noise value between -1 and 1. #### Response Example ```json { "noiseValue": 0.1234 } ``` ``` -------------------------------- ### Generator.Eval64() - Generate 3D Noise Source: https://context7.com/keinos/go-noise/llms.txt Generates a float64 noise value for three-dimensional coordinates. Useful for volumetric data, animations over time, or complex procedural generation. ```APIDOC ## Generator.Eval64(x, y, z float64) ### Description Generates a float64 noise value for three-dimensional coordinates. Useful for volumetric data, animations over time, or complex procedural generation. ### Method `generator.Eval64(x float64, y float64, z float64)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "fmt" "log" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 const scale = 50.0 gen, err := noise.New(noise.Perlin, seed) if err != nil { log.Fatal(err) } // Generate noise value for a 3D point x, y, z := 10.0, 20.0, 30.0 xx := x / scale yy := y / scale zz := z / scale noiseValue := gen.Eval64(xx, yy, zz) fmt.Printf("Noise value at (%.2f, %.2f, %.2f): %.4f\n", x, y, z, noiseValue) } ``` ### Response #### Success Response (200) - **noiseValue** (*float64*) - A noise value between -1 and 1. #### Response Example ```json { "noiseValue": -0.9876 } ``` ``` -------------------------------- ### 3D Perlin Noise Generation (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Shows how to generate a 3D noise value at position (x, y, z) using the Perlin noise algorithm. This is often used for animations where 'z' can represent time or depth. The output 'v' is a float64 between -1.0 and 1.0. ```go // Obtain the noise value at the position (x, y, z) // n, err := noise.New(noise.Perlin, seed) // v := n.Eval64(x, y, z) // v is between -1.0 and 1.0 of float64 ``` -------------------------------- ### Generator.Eval32() - Generate Noise with Float32 Source: https://context7.com/keinos/go-noise/llms.txt Generates float32 noise values. This function is suitable for memory-efficient applications or GPU-based computations. ```APIDOC ## Generator.Eval32() ### Description Generates float32 noise values for memory-efficient applications or GPU-based computations. ### Method N/A (This is a method of a Generator object, not a direct API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go // Example usage within a Go program: gen, err := noise.New(noise.OpenSimplex, seed) // ... noise1D := gen.Eval32(x / 10) noise2D := gen.Eval32(x/10, y/10) noise3D := gen.Eval32(1.0, 2.0, 3.0) ``` ### Response #### Success Response (200) N/A (This is a method call, not an HTTP response) #### Response Example ```go // The method returns a float32 noise value // Example: noise1D = 0.1234 ``` ``` -------------------------------- ### Generator.Eval64() - Generate 3D Noise Source: https://context7.com/keinos/go-noise/llms.txt Generates a float64 noise value for three-dimensional coordinates. This is useful for creating animated textures and volumetric effects. ```APIDOC ## Generator.Eval64() ### Description Generates a float64 noise value for three-dimensional coordinates, ideal for animated textures and volumetric effects. ### Method N/A (This is a method of a Generator object, not a direct API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go // Example usage within a Go program: gen, err := noise.New(noise.Perlin, seed) // ... noiseValue := gen.Eval64(xx, yy, zz) ``` ### Response #### Success Response (200) N/A (This is a method call, not an HTTP response) #### Response Example ```go // The method returns a float64 noise value // Example: noiseValue = 0.75234 ``` ``` -------------------------------- ### Generator.Eval64() - Generate 2D Noise Source: https://context7.com/keinos/go-noise/llms.txt Generates a float64 noise value for two-dimensional coordinates. Commonly used for creating heightmaps and procedural textures. ```APIDOC ## Generator.Eval64(x, y float64) ### Description Generates a float64 noise value for two-dimensional coordinates, commonly used for heightmaps and textures. ### Method `generator.Eval64(x float64, y float64)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```go package main import ( "fmt" "image" "image/color" "image/png" "log" "os" "github.com/KEINOS/go-noise" ) func main() { const seed = 100 const width, height = 256, 256 const scale = 50.0 gen, err := noise.New(noise.OpenSimplex, seed) if err != nil { log.Fatal(err) } // Create heightmap image img := image.NewGray(image.Rect(0, 0, width, height)) for y := 0; y < height; y++ { for x := 0; x < width; x++ { // Normalize coordinates xx := float64(x) / scale yy := float64(y) / scale // Get noise value [-1, 1] noiseValue := gen.Eval64(xx, yy) // Convert to grayscale [0, 255] grayValue := uint8((noiseValue + 1) / 2 * 255) img.SetGray(x, y, color.Gray{Y: grayValue}) } } // Save to file file, err := os.Create("heightmap.png") if err != nil { log.Fatal(err) } defer file.Close() if err := png.Encode(file, img); err != nil { log.Fatal(err) } fmt.Println("2D heightmap saved to heightmap.png") } ``` ### Response #### Success Response (200) - **noiseValue** (*float64*) - A noise value between -1 and 1. #### Response Example ```json { "noiseValue": 0.5678 } ``` ``` -------------------------------- ### Generate 3D Noise Value (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Generates a 3-dimensional noise value at a given position (x, y, z) using float32 or float64 precision. The output noise value is between -1.0 and 1.0. Inputs 'x', 'y', and 'z' should be of the same type (float32 or float64) as the chosen method. ```go c := genNoise.Eval32(x, y, z) // 3D noise. Obtain noise value at x, y, z. // c, x, y, z are float32. // Noise c is between -1.0 and 1.0. ``` ```go c := genNoise.Eval64(x, y, z) // 3D noise. Obtain noise value at x, y, z. // c, x, y, z are float64. // Noise c is between -1.0 and 1.0. ``` -------------------------------- ### Generate 2D Noise Value (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Generates a 2-dimensional noise value at a given position (x, y) using float32 or float64 precision. The output noise value ranges from -1.0 to 1.0. The inputs 'x' and 'y' are float32 or float64, matching the method's precision. ```go b := genNoise.Eval32(x, y) // 2D noise. Obtain noise value at x, y. // b, x, y are float32. // Noise b is between -1.0 and 1.0. ``` ```go b := genNoise.Eval64(x, y) // 2D noise. Obtain noise value at x, y. // b, x, y are float64. // Noise b is between -1.0 and 1.0. ``` -------------------------------- ### Generate 1D Noise Value (Go) Source: https://github.com/keinos/go-noise/blob/main/README.md Generates a 1-dimensional noise value at a given position 'x' using float32 or float64 precision. The output noise value is within the range of -1.0 to 1.0. The input 'x' is a float32 or float64, depending on the method used. ```go a := genNoise.Eval32(x) // 1D noise. Obtain noise value at x. // a, x are float32. // Noise a is between -1.0 and 1.0. ``` ```go a := genNoise.Eval64(x) // 1D noise. Obtain noise value at x. // a, x are float64. // Noise a is between -1.0 and 1.0. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.