perlin 0.1.0pre1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,14 +1,36 @@
1
1
  Perlin
2
2
  ======
3
3
 
4
- A Perlin noise implementation based off
5
- <http://freespace.virgin.net/hugo.elias/models/m_perlin.htm>. Implemented as a Ruby C extension, it is considerably faster than the pure Ruby equivalent, [perlin_noise](https://github.com/junegunn/perlin_noise).
4
+ A fast Perlin/Simplex noise generator.
5
+ Implemented as a Ruby C extension, it is considerably faster than the pure Ruby equivalent, [perlin_noise](https://github.com/junegunn/perlin_noise).
6
6
 
7
- - Written by Brian 'bojo' Jones <mojobojo@gmail.com>
8
- - Optimizations thanks to Camille Goudeseune, Univ of Illinois, <cog@illinois.edu>
7
+ By default, the noise generated uses Perlin's Simplex functions, but can produce "Classic" Perlin noise
8
+ (not recommended, since it is significantly slower).
9
+
10
+ If a large number of noise values are required, requesting chunks of values can be faster, which can then be iterated
11
+ through at leisure (or use the block version of #chunk).
12
+
13
+ - [Benchmarks](https://github.com/Spooner/ruby-perlin/blob/master/bench/benchmarks.txt)
14
+
15
+ CREDITS
16
+ -------
17
+
18
+ - Written by Brian 'bojo' Jones (mojobojo@gmail.com)
19
+ - Optimizations thanks to Camille Goudeseune, Univ of Illinois, (cog@illinois.edu)
9
20
  - Made into gem and extended by Bil Bas (bil.bagpuss@gmail.com)
10
21
 
11
22
  - [Simplex noise functions copyright (c) 2007-2012 Eliot Eshelman](http://www.6by9.net/b/2012/02/03/simplex-noise-for-c-and-python)
23
+ - "Classic" noise functions based on http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
24
+
25
+ USE CASES
26
+ ---------
27
+
28
+ One use for this gem would be to generate "randomness" for games, such as building levels for a rogue-alike game.
29
+
30
+ If generating textures, it is advised to use a Simplex noise shader instead of this gem, since shaders are considerably
31
+ faster than setting pixels, for example by using TexPlay. The issue is not so much that generating the noise is faster,
32
+ but that setting individual pixel colours from Ruby is very slow. However, if graphics shaders are not available, then
33
+ this could be used, but would be painfully slow for anything but tiny images.
12
34
 
13
35
  INSTALL
14
36
  -------
@@ -21,13 +43,28 @@ USAGE
21
43
  require 'perlin'
22
44
 
23
45
  # Takes values seed, persistence, and octaves
24
- noise = Perlin::Generator.new 123, 1.0, 1
46
+ gen = Perlin::Generator.new 123, 1.0, 1
25
47
 
26
- # Returns a 'height' value for (x, y)
27
- puts noise[10, 20] #=> 0.9004574418067932
48
+ # Returns a 'height' value for 2 or 3-dimensional noise.
49
+ gen[10, 20] #=> 0.0011919947855197324
50
+ gen[5, 22.2, 99.8] #=> 0.692631933498385
28
51
 
29
52
  # Returns a 2D array of 'heights' for a range (x, y, size_x, size_y, interval)
30
- arr = noise.chunk 1, 1, 2, 3, 1
53
+ noise = gen.chunk 1, 1, 2, 3, 1
54
+
55
+ noise[1][2] #=> 0.28406014362476045
56
+ p noise #= > [[-0.9227624778765608, -0.0016387049134645594, -0.4764434188330739],
57
+ # [0.24490384926510073, -0.4764434188330739, 0.28406014362476045]]
58
+
59
+
60
+ # Returns a 3D array of 'heights' for a range (x, y, size_x, size_y, interval)
61
+ noise = gen.chunk 0, 0, 0, 2, 3, 4, 0.5
62
+ noise.size #=> 2
63
+ noise[0].size #=> 3
64
+ noise[0][0].size #=> 4
65
+ noise[1][2][3] #=> -0.1585322813268602
66
+
67
+ # Can run in "Classic" Perlin mode (Not recommended - SLOW!)
31
68
 
32
- p arr #= > [[0.05753844603896141, -0.2208995521068573, 0.3973901569843292],
33
- # [0.1383310854434967, -0.22248442471027374, 0.15600799024105072]]
69
+ gen.classic = true
70
+ gen[10, 20] #=> -0.19936732947826385
data/Rakefile CHANGED
@@ -11,38 +11,9 @@ begin
11
11
  rescue LoadError
12
12
  end
13
13
 
14
- require File.expand_path('../lib/perlin/version', __FILE__)
15
-
16
14
  CLOBBER << "coverage"
17
15
 
18
- # somewhere in your Rakefile, define your gem spec
19
- spec = Gem::Specification.new do |s|
20
- s.name = 'perlin'
21
- s.version = Perlin::VERSION
22
- s.date = Time.now.strftime '%Y-%m-%d'
23
- s.authors = ["Brian 'bojo' Jones", 'Camille Goudeseune', 'Bil Bas']
24
-
25
- s.summary = 'Perlin Noise C extension'
26
- s.description = <<-END
27
- #{s.summary}
28
-
29
- A Perlin/Simplex noise implementation based of
30
- <http://freespace.virgin.net/hugo.elias/models/m_perlin.htm>. Implemented as a Ruby C extension.
31
- END
32
-
33
- s.email = %w<mojobojo@gmail.com>
34
- s.files = Dir.glob %w<CHANGELOG LICENSE Rakefile README.md lib/**/*.* lib ext/**/*.* examples/**/*.*>
35
- s.homepage = 'https://github.com/boj/ruby-perlin'
36
- s.licenses = %w<MIT>
37
- s.extensions << 'ext/perlin/extconf.rb'
38
- s.rubyforge_project = 'ruby-perlin'
39
- s.test_files = []
40
- s.has_rdoc = 'yard'
41
-
42
- s.add_development_dependency 'rake-compile', '~> 0.8.1'
43
- s.add_development_dependency 'simplecov', '~> 0.6.4'
44
- s.add_development_dependency 'launchy', '~> 2.1.0'
45
- end
16
+ spec = Gem::Specification.load Dir["*.gemspec"][0]
46
17
 
47
18
  Gem::PackageTask.new spec do
48
19
  end
@@ -9,7 +9,9 @@ dir_config(extension_name)
9
9
  $CFLAGS += ' -DRUBY_19' if RUBY_VERSION =~ /^1.9/
10
10
 
11
11
  # let's use c99
12
- #$CFLAGS += " -std=c99"
13
12
  $CFLAGS += " -std=gnu99"
14
13
 
14
+ # Avoid warnings since we are using C99, not C90!
15
+ $warnflags.gsub!('-Wdeclaration-after-statement', '') if $warnflags
16
+
15
17
  create_makefile(extension_name)
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perlin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0pre1
5
- prerelease: 5
4
+ version: 0.1.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian 'bojo' Jones
@@ -11,10 +11,58 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-07 00:00:00.000000000 Z
14
+ date: 2012-07-16 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: rake-compile
17
+ name: RedCloth
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 4.2.9
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: 4.2.9
32
+ - !ruby/object:Gem::Dependency
33
+ name: yard
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 0.8.2.1
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.8.2.1
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 2.10.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.10.0
64
+ - !ruby/object:Gem::Dependency
65
+ name: rake-compiler
18
66
  requirement: !ruby/object:Gem::Requirement
19
67
  none: false
20
68
  requirements:
@@ -81,19 +129,15 @@ files:
81
129
  - LICENSE
82
130
  - Rakefile
83
131
  - README.md
84
- - lib/perlin/1.9/perlin.so
85
- - lib/perlin/generator.rb
86
- - lib/perlin/version.rb
87
- - lib/perlin.rb
88
132
  - ext/perlin/classic.c
89
- - ext/perlin/classic.h
90
- - ext/perlin/extconf.rb
91
133
  - ext/perlin/generator.c
92
- - ext/perlin/generator.h
93
134
  - ext/perlin/perlin.c
94
- - ext/perlin/perlin.h
95
135
  - ext/perlin/simplex.c
136
+ - ext/perlin/classic.h
137
+ - ext/perlin/generator.h
138
+ - ext/perlin/perlin.h
96
139
  - ext/perlin/simplex.h
140
+ - ext/perlin/extconf.rb
97
141
  - examples/chunk_in_2d.rb
98
142
  - examples/chunk_in_3d.rb
99
143
  - examples/index_in_2d.rb
@@ -113,15 +157,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
157
  - - ! '>='
114
158
  - !ruby/object:Gem::Version
115
159
  version: '0'
160
+ segments:
161
+ - 0
162
+ hash: 176652013
116
163
  required_rubygems_version: !ruby/object:Gem::Requirement
117
164
  none: false
118
165
  requirements:
119
- - - ! '>'
166
+ - - ! '>='
120
167
  - !ruby/object:Gem::Version
121
- version: 1.3.1
168
+ version: '0'
169
+ segments:
170
+ - 0
171
+ hash: 176652013
122
172
  requirements: []
123
173
  rubyforge_project: ruby-perlin
124
- rubygems_version: 1.8.23
174
+ rubygems_version: 1.8.24
125
175
  signing_key:
126
176
  specification_version: 3
127
177
  summary: Perlin Noise C extension
@@ -1,13 +0,0 @@
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
@@ -1,161 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- # Perlin noise generation.
2
- module Perlin
3
- # Current version of the gem.
4
- VERSION = "0.1.0pre1"
5
- end