Class: Worldgen::HeightMap
- Inherits:
-
Object
- Object
- Worldgen::HeightMap
- Defined in:
- lib/worldgen/heightmap.rb,
ext/worldgen/heightmap.c
Overview
A square heightmap
Defined Under Namespace
Classes: HeightmapData
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#each_height ⇒ Object
Iterate over all the points in the heightmap.
-
#initialize(size) ⇒ HeightMap
constructor
Create a new square heightmap.
-
#num_points ⇒ Object
Get the number of points within the heightmap.
Constructor Details
#initialize(size) ⇒ HeightMap
Create a new square heightmap. Arguments:
-
size - the width/height of the map
13 14 15 16 |
# File 'lib/worldgen/heightmap.rb', line 13 def initialize size @size = size initialize_native(size) end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/worldgen/heightmap.rb', line 8 def size @size end |
Instance Method Details
#each_height ⇒ Object
Iterate over all the points in the heightmap. Example: “‘ heightmap.each_height do |x, y, height|
puts "Height at (#{x}, #{y}) is #{height}"
end
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'ext/worldgen/heightmap.c', line 76 VALUE each_height(VALUE self) { heightmap map = get_heights(self); heightmap_points ptr = map.heights; VALUE args = rb_ary_new2(3); int size = get_size(self); int x, y; for (x = 0; x < size; x++) { rb_ary_store(args, 0, INT2FIX(x)); for (y = 0; y < size; y++) { rb_ary_store(args, 1, INT2FIX(y)); rb_ary_store(args, 2, DBL2NUM(*ptr++)); rb_yield(args); } } return self; } |
#num_points ⇒ Object
Get the number of points within the heightmap. Right now this is a very simple calculation of size * size.
64 65 66 |
# File 'ext/worldgen/heightmap.c', line 64 VALUE num_points_wrapped(VALUE self) { return INT2FIX(num_points(FIX2INT(rb_iv_get(self, "@size")))); } |