Class: Perlin::Generator
- Inherits:
-
Object
- Object
- Perlin::Generator
- Defined in:
- lib/perlin/generator.rb
Overview
Perlin noise generator.
Instance Attribute Summary collapse
-
#octave ⇒ Integer
Number of octaves (or iterations) of noise to generate (>= 1).
-
#persistence ⇒ Float
Amount of persistence of noise through each octave.
-
#seed ⇒ Integer
Seed value for the noise pattern (>= 0).
Instance Method Summary collapse
- #classic=(value) ⇒ Boolean
-
#classic? ⇒ Boolean
True for Classic noise, false for Simplex noise.
-
#initialize(seed, persistence, octave, options = {}) ⇒ Object
constructor
Create a noise generator.
-
#simplex? ⇒ Boolean
True for Simplex noise, false for Classic noise.
Constructor Details
#initialize(seed, persistence, octave, options = {}) ⇒ Object
Create a noise generator.
Using the same seed will always produce the same pattern. Animate a perlin ‘texture’ by altering the seed based on time.
|
# File 'lib/perlin/generator.rb', line 26
|
Instance Attribute Details
#octave ⇒ Integer
Number of octaves (or iterations) of noise to generate (>= 1)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/perlin/generator.rb', line 15 class Generator # @!method classic? # @return [Boolean] True for Classic noise, false for Simplex noise. # @!method classic=(value) # @param value [Boolean] True for Classic noise, false for Simplex noise. # @return [Boolean] # @return [Boolean] True for Simplex noise, false for Classic noise. def simplex?; !classic? end # @!method initialize(seed, persistence, octave, options={}) # Create a noise generator. # # Using the same seed will always produce the same pattern. Animate a perlin 'texture' by altering the seed based on time. # # @param seed [Integer] Seed value to create a different pattern (must be >= 0). # @param persistence [Float] Used to generate different frequencies/amplitudes of output . # @param octave [Integer] Number of iterations to run (higher number of octaves takes more time) (must be >= 1) # @option options :classic [Boolean] (false) Whether to use the slower Classic algorithm, rather than default (and much faster) Simplex. # @overload chunk(x, y, steps_x, steps_y, interval) # Calculates a rectangular section of height (n) values and returns them as a 2D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # arr = noise.chunk 1, 1, 2, 3, 1.5 # # # access position 1, 2 (remember that arr is offset by the x, y value of the chunk) # puts arr[0, 1] #=> -0.2208995521068573 # # p arr #= > [[0.05753844603896141, -0.2208995521068573, 0.3973901569843292], [0.1383310854434967, -0.22248442471027374, 0.15600799024105072]] # # @param x [Float] # @param y [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param interval [Float] # # @return [Array<Array<Float>>] height (n) values within the rectangle. # # @overload chunk(x, y, steps_x, steps_y, interval) {|h, x, y| } # Calculates a rectangular section of height (n) values and returns them as a 2D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.5, 3 # noise.chunk 1.0, 2.3, 3, 2, 1.5 do |h, x, y| # # Use the height value, which is at x, y. # end # # @param x [Float] # @param y [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param interval [Float] # # @yieldparam h [Float] Height at x, y # @yieldparam x [Float] # @yieldparam y [Float] # # @return [nil] # # @overload chunk(x, y, z, size_x, size_y, size_z, interval) # Calculates a rectangular section of height (n) values and returns them as a 3D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.5, 5 # arr = noise.chunk 6.0, 5.0, 4.0, 3, 2, 1, 1.5 # # # access position 2, 1, 0 (remember that arr is offset by the x, y and z value of the chunk) # puts arr[2, 1, 0] #=> # # p arr #= > # # @param x [Float] # @param y [Float] # @param z [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param steps_z [Integer] # @param interval [Float] # # @return [Array<Array<Float>>] height (n) values within the rectangle. # # @overload chunk(x, y, z, size_x, size_y, size_z, interval) {|h, x, y| } # Calculates a rectangular section of height (n) values and returns them as a 3D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.8, 3 # noise.chunk 6.0, 5.0, 4.0, 3, 2, 1, 1.5 do |h, x, y, z| # # Use the height value, which is at x, y, z. # end # # @param x [Float] # @param y [Float] # @param z [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param steps_z [Integer] # @param interval [Float] # # @yieldparam h [Float] Height at x, y, z # @yieldparam x [Float] # @yieldparam y [Float] # @yieldparam z [Float] # # @return [nil] # Gets height (n) at a point in 2D or 3D space. # # This is much slower, if accessing many points, than using {#chunk} # # @overload [](x, y) # Gets height (n) value at a specific 2D position. # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # # # Returns a 'height' value for (x, y) # puts noise[10, 20] #=> 0.9004574418067932 # # @param x [Float] # @param y [Float] # @return [Float] height (n) value at the position # # @overload [](x, y, z) # Gets height (n) value at a specific 3D position. # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # # # Returns a 'height' value for (x, y, z) # puts noise[10, 20, 30] #=> 0.017745036631822586 # # @param x [Float] # @param y [Float] # @param z [Float] # @return [Float] height (n) value at the position alias_method :run, :[] end |
#persistence ⇒ Float
Amount of persistence of noise through each octave
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/perlin/generator.rb', line 15 class Generator # @!method classic? # @return [Boolean] True for Classic noise, false for Simplex noise. # @!method classic=(value) # @param value [Boolean] True for Classic noise, false for Simplex noise. # @return [Boolean] # @return [Boolean] True for Simplex noise, false for Classic noise. def simplex?; !classic? end # @!method initialize(seed, persistence, octave, options={}) # Create a noise generator. # # Using the same seed will always produce the same pattern. Animate a perlin 'texture' by altering the seed based on time. # # @param seed [Integer] Seed value to create a different pattern (must be >= 0). # @param persistence [Float] Used to generate different frequencies/amplitudes of output . # @param octave [Integer] Number of iterations to run (higher number of octaves takes more time) (must be >= 1) # @option options :classic [Boolean] (false) Whether to use the slower Classic algorithm, rather than default (and much faster) Simplex. # @overload chunk(x, y, steps_x, steps_y, interval) # Calculates a rectangular section of height (n) values and returns them as a 2D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # arr = noise.chunk 1, 1, 2, 3, 1.5 # # # access position 1, 2 (remember that arr is offset by the x, y value of the chunk) # puts arr[0, 1] #=> -0.2208995521068573 # # p arr #= > [[0.05753844603896141, -0.2208995521068573, 0.3973901569843292], [0.1383310854434967, -0.22248442471027374, 0.15600799024105072]] # # @param x [Float] # @param y [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param interval [Float] # # @return [Array<Array<Float>>] height (n) values within the rectangle. # # @overload chunk(x, y, steps_x, steps_y, interval) {|h, x, y| } # Calculates a rectangular section of height (n) values and returns them as a 2D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.5, 3 # noise.chunk 1.0, 2.3, 3, 2, 1.5 do |h, x, y| # # Use the height value, which is at x, y. # end # # @param x [Float] # @param y [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param interval [Float] # # @yieldparam h [Float] Height at x, y # @yieldparam x [Float] # @yieldparam y [Float] # # @return [nil] # # @overload chunk(x, y, z, size_x, size_y, size_z, interval) # Calculates a rectangular section of height (n) values and returns them as a 3D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.5, 5 # arr = noise.chunk 6.0, 5.0, 4.0, 3, 2, 1, 1.5 # # # access position 2, 1, 0 (remember that arr is offset by the x, y and z value of the chunk) # puts arr[2, 1, 0] #=> # # p arr #= > # # @param x [Float] # @param y [Float] # @param z [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param steps_z [Integer] # @param interval [Float] # # @return [Array<Array<Float>>] height (n) values within the rectangle. # # @overload chunk(x, y, z, size_x, size_y, size_z, interval) {|h, x, y| } # Calculates a rectangular section of height (n) values and returns them as a 3D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.8, 3 # noise.chunk 6.0, 5.0, 4.0, 3, 2, 1, 1.5 do |h, x, y, z| # # Use the height value, which is at x, y, z. # end # # @param x [Float] # @param y [Float] # @param z [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param steps_z [Integer] # @param interval [Float] # # @yieldparam h [Float] Height at x, y, z # @yieldparam x [Float] # @yieldparam y [Float] # @yieldparam z [Float] # # @return [nil] # Gets height (n) at a point in 2D or 3D space. # # This is much slower, if accessing many points, than using {#chunk} # # @overload [](x, y) # Gets height (n) value at a specific 2D position. # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # # # Returns a 'height' value for (x, y) # puts noise[10, 20] #=> 0.9004574418067932 # # @param x [Float] # @param y [Float] # @return [Float] height (n) value at the position # # @overload [](x, y, z) # Gets height (n) value at a specific 3D position. # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # # # Returns a 'height' value for (x, y, z) # puts noise[10, 20, 30] #=> 0.017745036631822586 # # @param x [Float] # @param y [Float] # @param z [Float] # @return [Float] height (n) value at the position alias_method :run, :[] end |
#seed ⇒ Integer
Seed value for the noise pattern (>= 0)
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/perlin/generator.rb', line 15 class Generator # @!method classic? # @return [Boolean] True for Classic noise, false for Simplex noise. # @!method classic=(value) # @param value [Boolean] True for Classic noise, false for Simplex noise. # @return [Boolean] # @return [Boolean] True for Simplex noise, false for Classic noise. def simplex?; !classic? end # @!method initialize(seed, persistence, octave, options={}) # Create a noise generator. # # Using the same seed will always produce the same pattern. Animate a perlin 'texture' by altering the seed based on time. # # @param seed [Integer] Seed value to create a different pattern (must be >= 0). # @param persistence [Float] Used to generate different frequencies/amplitudes of output . # @param octave [Integer] Number of iterations to run (higher number of octaves takes more time) (must be >= 1) # @option options :classic [Boolean] (false) Whether to use the slower Classic algorithm, rather than default (and much faster) Simplex. # @overload chunk(x, y, steps_x, steps_y, interval) # Calculates a rectangular section of height (n) values and returns them as a 2D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # arr = noise.chunk 1, 1, 2, 3, 1.5 # # # access position 1, 2 (remember that arr is offset by the x, y value of the chunk) # puts arr[0, 1] #=> -0.2208995521068573 # # p arr #= > [[0.05753844603896141, -0.2208995521068573, 0.3973901569843292], [0.1383310854434967, -0.22248442471027374, 0.15600799024105072]] # # @param x [Float] # @param y [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param interval [Float] # # @return [Array<Array<Float>>] height (n) values within the rectangle. # # @overload chunk(x, y, steps_x, steps_y, interval) {|h, x, y| } # Calculates a rectangular section of height (n) values and returns them as a 2D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.5, 3 # noise.chunk 1.0, 2.3, 3, 2, 1.5 do |h, x, y| # # Use the height value, which is at x, y. # end # # @param x [Float] # @param y [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param interval [Float] # # @yieldparam h [Float] Height at x, y # @yieldparam x [Float] # @yieldparam y [Float] # # @return [nil] # # @overload chunk(x, y, z, size_x, size_y, size_z, interval) # Calculates a rectangular section of height (n) values and returns them as a 3D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.5, 5 # arr = noise.chunk 6.0, 5.0, 4.0, 3, 2, 1, 1.5 # # # access position 2, 1, 0 (remember that arr is offset by the x, y and z value of the chunk) # puts arr[2, 1, 0] #=> # # p arr #= > # # @param x [Float] # @param y [Float] # @param z [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param steps_z [Integer] # @param interval [Float] # # @return [Array<Array<Float>>] height (n) values within the rectangle. # # @overload chunk(x, y, z, size_x, size_y, size_z, interval) {|h, x, y| } # Calculates a rectangular section of height (n) values and returns them as a 3D array. # # This is much faster than accessing each point separately using {#[]} # # @example # noise = Perlin::Generator.new 123, 0.8, 3 # noise.chunk 6.0, 5.0, 4.0, 3, 2, 1, 1.5 do |h, x, y, z| # # Use the height value, which is at x, y, z. # end # # @param x [Float] # @param y [Float] # @param z [Float] # @param steps_x [Integer] # @param steps_y [Integer] # @param steps_z [Integer] # @param interval [Float] # # @yieldparam h [Float] Height at x, y, z # @yieldparam x [Float] # @yieldparam y [Float] # @yieldparam z [Float] # # @return [nil] # Gets height (n) at a point in 2D or 3D space. # # This is much slower, if accessing many points, than using {#chunk} # # @overload [](x, y) # Gets height (n) value at a specific 2D position. # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # # # Returns a 'height' value for (x, y) # puts noise[10, 20] #=> 0.9004574418067932 # # @param x [Float] # @param y [Float] # @return [Float] height (n) value at the position # # @overload [](x, y, z) # Gets height (n) value at a specific 3D position. # # @example # noise = Perlin::Generator.new 123, 1.0, 1 # # # Returns a 'height' value for (x, y, z) # puts noise[10, 20, 30] #=> 0.017745036631822586 # # @param x [Float] # @param y [Float] # @param z [Float] # @return [Float] height (n) value at the position alias_method :run, :[] end |
Instance Method Details
#classic=(value) ⇒ Boolean
|
# File 'lib/perlin/generator.rb', line 19
|
#classic? ⇒ Boolean
Returns True for Classic noise, false for Simplex noise.
|
# File 'lib/perlin/generator.rb', line 16
|
#simplex? ⇒ Boolean
Returns True for Simplex noise, false for Classic noise.
24 |
# File 'lib/perlin/generator.rb', line 24 def simplex?; !classic? end |