perlin 0.1.0pre1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,196 @@
1
+ /* Copyright (c) 2007-2012 Eliot Eshelman
2
+ *
3
+ * This program is free software: you can redistribute it and/or modify
4
+ * it under the terms of the GNU General Public License as published by
5
+ * the Free Software Foundation, either version 3 of the License, or
6
+ * (at your option) any later version.
7
+ *
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU General Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU General Public License
14
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ *
16
+ */
17
+
18
+
19
+ #ifndef SIMPLEX_H_
20
+ #define SIMPLEX_H_
21
+
22
+ #include <math.h>
23
+
24
+
25
+ /* 2D, 3D and 4D Simplex Noise functions return 'random' values in (-1, 1).
26
+
27
+ This algorithm was originally designed by Ken Perlin, but my code has been
28
+ adapted from the implementation written by Stefan Gustavson (stegu@itn.liu.se)
29
+
30
+ Raw Simplex noise functions return the value generated by Ken's algorithm.
31
+
32
+ Scaled Raw Simplex noise functions adjust the range of values returned from the
33
+ traditional (-1, 1) to whichever bounds are passed to the function.
34
+
35
+ Multi-Octave Simplex noise functions compine multiple noise values to create a
36
+ more complex result. Each successive layer of noise is adjusted and scaled.
37
+
38
+ Scaled Multi-Octave Simplex noise functions scale the values returned from the
39
+ traditional (-1,1) range to whichever range is passed to the function.
40
+
41
+ In many cases, you may think you only need a 1D noise function, but in practice
42
+ 2D is almost always better. For instance, if you're using the current frame
43
+ number as the parameter for the noise, all objects will end up with the same
44
+ noise value at each frame. By adding a second parameter on the second
45
+ dimension, you can ensure that each gets a unique noise value and they don't
46
+ all look identical.
47
+ */
48
+
49
+
50
+ // Multi-octave Simplex noise
51
+ // For each octave, a higher frequency/lower amplitude function will be added to the original.
52
+ // The higher the persistence [0-1], the more of each succeeding octave will be added.
53
+ float octave_noise_2d(const float octaves,
54
+ const float persistence,
55
+ const float scale,
56
+ const float x,
57
+ const float y);
58
+ float octave_noise_3d(const float octaves,
59
+ const float persistence,
60
+ const float scale,
61
+ const float x,
62
+ const float y,
63
+ const float z);
64
+ float octave_noise_4d(const float octaves,
65
+ const float persistence,
66
+ const float scale,
67
+ const float x,
68
+ const float y,
69
+ const float z,
70
+ const float w);
71
+
72
+
73
+ // Scaled Multi-octave Simplex noise
74
+ // The result will be between the two parameters passed.
75
+ float scaled_octave_noise_2d( const float octaves,
76
+ const float persistence,
77
+ const float scale,
78
+ const float loBound,
79
+ const float hiBound,
80
+ const float x,
81
+ const float y);
82
+ float scaled_octave_noise_3d( const float octaves,
83
+ const float persistence,
84
+ const float scale,
85
+ const float loBound,
86
+ const float hiBound,
87
+ const float x,
88
+ const float y,
89
+ const float z);
90
+ float scaled_octave_noise_4d( const float octaves,
91
+ const float persistence,
92
+ const float scale,
93
+ const float loBound,
94
+ const float hiBound,
95
+ const float x,
96
+ const float y,
97
+ const float z,
98
+ const float w);
99
+
100
+ // Scaled Raw Simplex noise
101
+ // The result will be between the two parameters passed.
102
+ float scaled_raw_noise_2d( const float loBound,
103
+ const float hiBound,
104
+ const float x,
105
+ const float y);
106
+ float scaled_raw_noise_3d( const float loBound,
107
+ const float hiBound,
108
+ const float x,
109
+ const float y,
110
+ const float z);
111
+ float scaled_raw_noise_4d( const float loBound,
112
+ const float hiBound,
113
+ const float x,
114
+ const float y,
115
+ const float z,
116
+ const float w);
117
+
118
+
119
+ // Raw Simplex noise - a single noise value.
120
+ float raw_noise_2d(const float x, const float y);
121
+ float raw_noise_3d(const float x, const float y, const float z);
122
+ float raw_noise_4d(const float x, const float y, const float, const float w);
123
+
124
+
125
+ int fastfloor(const float x);
126
+
127
+ float dot2(const int* g, const float x, const float y);
128
+ float dot3(const int* g, const float x, const float y, const float z);
129
+ float dot4(const int* g, const float x, const float y, const float z, const float w);
130
+
131
+
132
+ // The gradients are the midpoints of the vertices of a cube.
133
+ static const int grad3[12][3] = {
134
+ {1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0},
135
+ {1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1},
136
+ {0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1}
137
+ };
138
+
139
+
140
+ // The gradients are the midpoints of the vertices of a hypercube.
141
+ static const int grad4[32][4]= {
142
+ {0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1},
143
+ {0,-1,1,1}, {0,-1,1,-1}, {0,-1,-1,1}, {0,-1,-1,-1},
144
+ {1,0,1,1}, {1,0,1,-1}, {1,0,-1,1}, {1,0,-1,-1},
145
+ {-1,0,1,1}, {-1,0,1,-1}, {-1,0,-1,1}, {-1,0,-1,-1},
146
+ {1,1,0,1}, {1,1,0,-1}, {1,-1,0,1}, {1,-1,0,-1},
147
+ {-1,1,0,1}, {-1,1,0,-1}, {-1,-1,0,1}, {-1,-1,0,-1},
148
+ {1,1,1,0}, {1,1,-1,0}, {1,-1,1,0}, {1,-1,-1,0},
149
+ {-1,1,1,0}, {-1,1,-1,0}, {-1,-1,1,0}, {-1,-1,-1,0}
150
+ };
151
+
152
+
153
+ // Permutation table. The same list is repeated twice.
154
+ static const int perm[512] = {
155
+ 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,
156
+ 8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,
157
+ 35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,
158
+ 134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,
159
+ 55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 89,
160
+ 18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,
161
+ 250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,
162
+ 189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,
163
+ 172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,
164
+ 228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,
165
+ 107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,
166
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180,
167
+
168
+ 151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,
169
+ 8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,
170
+ 35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,
171
+ 134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,
172
+ 55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208, 89,
173
+ 18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,
174
+ 250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,
175
+ 189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,
176
+ 172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,
177
+ 228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,
178
+ 107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,
179
+ 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180
180
+ };
181
+
182
+
183
+ // A lookup table to traverse the simplex around a given point in 4D.
184
+ static const int simplex[64][4] = {
185
+ {0,1,2,3},{0,1,3,2},{0,0,0,0},{0,2,3,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,2,3,0},
186
+ {0,2,1,3},{0,0,0,0},{0,3,1,2},{0,3,2,1},{0,0,0,0},{0,0,0,0},{0,0,0,0},{1,3,2,0},
187
+ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
188
+ {1,2,0,3},{0,0,0,0},{1,3,0,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,3,0,1},{2,3,1,0},
189
+ {1,0,2,3},{1,0,3,2},{0,0,0,0},{0,0,0,0},{0,0,0,0},{2,0,3,1},{0,0,0,0},{2,1,3,0},
190
+ {0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},
191
+ {2,0,1,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,0,1,2},{3,0,2,1},{0,0,0,0},{3,1,2,0},
192
+ {2,1,0,3},{0,0,0,0},{0,0,0,0},{0,0,0,0},{3,1,0,2},{0,0,0,0},{3,2,0,1},{3,2,1,0}
193
+ };
194
+
195
+
196
+ #endif /*SIMPLEX_H_*/
data/lib/perlin.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'perlin/version'
2
+
3
+ begin
4
+ RUBY_VERSION =~ /(\d+.\d+)/
5
+ require "perlin/#{$1}/perlin.so"
6
+ rescue LoadError
7
+ require "perlin/perlin.so"
8
+ end
9
+
10
+ require 'perlin/generator'
11
+
12
+ module Perlin
13
+ end
Binary file
@@ -0,0 +1,161 @@
1
+ module Perlin
2
+ # Perlin noise generator.
3
+ #
4
+ # @!attribute [rw] seed
5
+ # @return [Integer]
6
+ #
7
+ # @!attribute [r] persistence
8
+ # @return [Float]
9
+ #
10
+ # @!attribute [r] octave
11
+ # @return [Integer]
12
+ class Generator
13
+ attr_reader :seed, :octave, :persistence
14
+ def classic?; @classic; end
15
+
16
+ # @!method initialize(seed, persistence, octave)
17
+ # Create a noise generator.
18
+ #
19
+ # Using the same seed will always produce the same pattern. Animate a perlin 'texture' by altering the seed based on time.
20
+ #
21
+ # @param seed [Integer] Seed value to create a different pattern.
22
+ # @param persistence [Float] Used to generate different frequencies/amplitudes of output.
23
+ # @param octave [Integer] Number of iterations to run (higher number of octaves takes more time)
24
+ # @option options :classic [Boolean] (false) Whether to use the slower Classic algorithm, rather than default (and much faster) Simplex.
25
+ def initialize(seed, persistence, octave, options = {})
26
+ options = {
27
+ :classic => false,
28
+ }.merge! options
29
+
30
+ initialize_(seed, persistence, octave, options[:classic])
31
+ end
32
+ protected :initialize_ # Underlying C implementation.
33
+
34
+ # @overload chunk(x, y, steps_x, steps_y, interval)
35
+ # Calculates a rectangular section of height (n) values and returns them as a 2D array.
36
+ #
37
+ # This is much faster than accessing each point separately using {#[]}
38
+ #
39
+ # @example
40
+ # noise = Perlin::Generator.new 123, 1.0, 1
41
+ # arr = noise.chunk 1, 1, 2, 3, 1.5
42
+ #
43
+ # # access position 1, 2 (remember that arr is offset by the x, y value of the chunk)
44
+ # puts arr[0, 1] #=> -0.2208995521068573
45
+ #
46
+ # p arr #= > [[0.05753844603896141, -0.2208995521068573, 0.3973901569843292], [0.1383310854434967, -0.22248442471027374, 0.15600799024105072]]
47
+ #
48
+ # @param x [Float]
49
+ # @param y [Float]
50
+ # @param steps_x [Integer]
51
+ # @param steps_y [Integer]
52
+ # @param interval [Float]
53
+ #
54
+ # @return [Array<Array<Float>>] height (n) values within the rectangle.
55
+ #
56
+ # @overload chunk(x, y, steps_x, steps_y, interval) {|h, x, y| }
57
+ # Calculates a rectangular section of height (n) values and returns them as a 2D array.
58
+ #
59
+ # This is much faster than accessing each point separately using {#[]}
60
+ #
61
+ # @example
62
+ # noise = Perlin::Generator.new 123, 0.5, 3
63
+ # noise.chunk 1.0, 2.3, 3, 2, 1.5 do |h, x, y|
64
+ # # Use the height value, which is at x, y.
65
+ # end
66
+ #
67
+ # @param x [Float]
68
+ # @param y [Float]
69
+ # @param steps_x [Integer]
70
+ # @param steps_y [Integer]
71
+ # @param interval [Float]
72
+ #
73
+ # @yieldparam h [Float] Height at x, y
74
+ # @yieldparam x [Float]
75
+ # @yieldparam y [Float]
76
+ #
77
+ # @return [nil]
78
+ #
79
+ # @overload chunk(x, y, z, size_x, size_y, size_z, interval)
80
+ # Calculates a rectangular section of height (n) values and returns them as a 3D array.
81
+ #
82
+ # This is much faster than accessing each point separately using {#[]}
83
+ #
84
+ # @example
85
+ # noise = Perlin::Generator.new 123, 0.5, 5
86
+ # arr = noise.chunk 6.0, 5.0, 4.0, 3, 2, 1, 1.5
87
+ #
88
+ # # access position 2, 1, 0 (remember that arr is offset by the x, y and z value of the chunk)
89
+ # puts arr[2, 1, 0] #=>
90
+ #
91
+ # p arr #= >
92
+ #
93
+ # @param x [Float]
94
+ # @param y [Float]
95
+ # @param z [Float]
96
+ # @param steps_x [Integer]
97
+ # @param steps_y [Integer]
98
+ # @param steps_z [Integer]
99
+ # @param interval [Float]
100
+ #
101
+ # @return [Array<Array<Float>>] height (n) values within the rectangle.
102
+ #
103
+ # @overload chunk(x, y, z, size_x, size_y, size_z, interval) {|h, x, y| }
104
+ # Calculates a rectangular section of height (n) values and returns them as a 3D array.
105
+ #
106
+ # This is much faster than accessing each point separately using {#[]}
107
+ #
108
+ # @example
109
+ # noise = Perlin::Generator.new 123, 0.8, 3
110
+ # noise.chunk 6.0, 5.0, 4.0, 3, 2, 1, 1.5 do |h, x, y, z|
111
+ # # Use the height value, which is at x, y, z.
112
+ # end
113
+ #
114
+ # @param x [Float]
115
+ # @param y [Float]
116
+ # @param z [Float]
117
+ # @param steps_x [Integer]
118
+ # @param steps_y [Integer]
119
+ # @param steps_z [Integer]
120
+ # @param interval [Float]
121
+ #
122
+ # @yieldparam h [Float] Height at x, y, z
123
+ # @yieldparam x [Float]
124
+ # @yieldparam y [Float]
125
+ # @yieldparam z [Float]
126
+ #
127
+ # @return [nil]
128
+
129
+ # Gets height (n) at a point in 2D or 3D space.
130
+ #
131
+ # This is much slower, if accessing many points, than using {#chunk}
132
+ #
133
+ # @overload [](x, y)
134
+ # Gets height (n) value at a specific 2D position.
135
+ #
136
+ # @example
137
+ # noise = Perlin::Generator.new 123, 1.0, 1
138
+ #
139
+ # # Returns a 'height' value for (x, y)
140
+ # puts noise[10, 20] #=> 0.9004574418067932
141
+ #
142
+ # @param x [Float]
143
+ # @param y [Float]
144
+ # @return [Float] height (n) value at the position
145
+ #
146
+ # @overload [](x, y, z)
147
+ # Gets height (n) value at a specific 3D position.
148
+ #
149
+ # @example
150
+ # noise = Perlin::Generator.new 123, 1.0, 1
151
+ #
152
+ # # Returns a 'height' value for (x, y, z)
153
+ # puts noise[10, 20, 30] #=> 0.017745036631822586
154
+ #
155
+ # @param x [Float]
156
+ # @param y [Float]
157
+ # @param z [Float]
158
+ # @return [Float] height (n) value at the position
159
+ alias_method :run, :[]
160
+ end
161
+ end
@@ -0,0 +1,5 @@
1
+ # Perlin noise generation.
2
+ module Perlin
3
+ # Current version of the gem.
4
+ VERSION = "0.1.0pre1"
5
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: perlin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0pre1
5
+ prerelease: 5
6
+ platform: x86-mingw32
7
+ authors:
8
+ - Brian 'bojo' Jones
9
+ - Camille Goudeseune
10
+ - Bil Bas
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-07-07 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rake-compile
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.8.1
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: 0.8.1
32
+ - !ruby/object:Gem::Dependency
33
+ name: simplecov
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 0.6.4
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.4
48
+ - !ruby/object:Gem::Dependency
49
+ name: launchy
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 2.1.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: 2.1.0
64
+ description: ! 'Perlin Noise C extension
65
+
66
+
67
+ A Perlin/Simplex noise implementation based of
68
+
69
+ <http://freespace.virgin.net/hugo.elias/models/m_perlin.htm>. Implemented as a Ruby
70
+ C extension.
71
+
72
+ '
73
+ email:
74
+ - mojobojo@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - CHANGELOG
80
+ - LICENSE
81
+ - Rakefile
82
+ - README.md
83
+ - lib/perlin/1.9/perlin.so
84
+ - lib/perlin/generator.rb
85
+ - lib/perlin/version.rb
86
+ - lib/perlin.rb
87
+ - ext/perlin/classic.c
88
+ - ext/perlin/classic.h
89
+ - ext/perlin/extconf.rb
90
+ - ext/perlin/generator.c
91
+ - ext/perlin/generator.h
92
+ - ext/perlin/perlin.c
93
+ - ext/perlin/perlin.h
94
+ - ext/perlin/simplex.c
95
+ - ext/perlin/simplex.h
96
+ - examples/chunk_in_2d.rb
97
+ - examples/chunk_in_3d.rb
98
+ - examples/index_in_2d.rb
99
+ - examples/index_in_3d.rb
100
+ - examples/ogl/README.md
101
+ - examples/ogl/run.rb
102
+ homepage: https://github.com/boj/ruby-perlin
103
+ licenses:
104
+ - MIT
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>'
119
+ - !ruby/object:Gem::Version
120
+ version: 1.3.1
121
+ requirements: []
122
+ rubyforge_project: ruby-perlin
123
+ rubygems_version: 1.8.23
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Perlin Noise C extension
127
+ test_files: []