Module: Worldgen::Render
- Defined in:
- lib/worldgen/render.rb
Class Method Summary collapse
-
.heightmap(map, filename) ⇒ Object
Render a heightmap to a grayscale file.
Class Method Details
.heightmap(map, filename) ⇒ Object
Render a heightmap to a grayscale file. Arguments:
-
map - The heightmap to render
-
filename - The filename to use. Image format will be inferred from the filename
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/worldgen/render.rb', line 8 def self.heightmap map, filename # loading each one in is crazy slow, just throw it into a pixel map image = Magick::Image.new(map.size, map.size) { self.background_color = "black" } map.each_height do |x, y, pix_height| grey = ("%2X" % (pix_height * 255).round) * 3 image.pixel_color x, y, "##{grey}" end #image.display image.write filename end |