Module: Worldgen::Render

Defined in:
lib/worldgen/render.rb

Class Method Summary collapse

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
# 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.write filename
end

.platemap(map, filename) ⇒ Object

Render a platemap to a file. Each plate has a separate colour - this will only work for up to 16 plates, after that everything will be black.

Arguments:

  • map - the plate map to render

  • filename - the filename to output to



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/worldgen/render.rb', line 26

def self.platemap map, filename
  image = Magick::Image.new(map.size, map.size) { self.background_color = "black" }

  # draw plates
  colours = [
    "#FF0000", "#0000FF", "#FFFF00", "#00FF00",
    "#FF6600", "#FF00FF", "#00FFFF", "#CCCCCC",
    "#006600", "#000066", "#660066", "#666600",
    "#CCCCCC", "#FFFFFF", "#000000", "#CCCCFF"
  ]
  map.each_plate_point do |x, y, plate|
    begin
      image.pixel_color x, y, (colours[plate] or "#000000")
    rescue
      puts "colour fail"
      puts [x, y, plate, colours[plate]].inspect
    end
  end

  image.write filename
end