-
Notifications
You must be signed in to change notification settings - Fork 8
/
draw_suppression_maps
executable file
·66 lines (57 loc) · 1.66 KB
/
draw_suppression_maps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby
require "RMagick"
require_relative "../lib/paradox"
require_relative "game_map"
class DrawSuppressionMap < ParadoxGame
include GameMap
def suppression_color
@suppression_color ||= begin
colors = %W[
008080 339384 50a78a 6cbc92 88cf9b a8e1aa cef2be ffffe0 ffd8cd ffaeb5 f78599 e65f7b cf3b59 b11732 8b0000
].map{|c| c.scan(/../).map(&:hex)}
ht = {}
ht.default = colors[-1]
ht[0] = [255,255,255]
colors.each_with_index do |c,i|
ht[i+1] = c
end
ht
end
end
def state_id_to_cav(state_id, mod)
suppression = (state_to_vp_total[state_id] * mod).floor
(suppression/2.0).ceil
end
def suppression_color_map(mod)
state_based_color_map do |state_id|
suppression_color[state_id_to_cav(state_id, mod)]
end
end
def add_suppression_labels(img, mod)
text = Magick::Draw.new
text.font_family = 'helvetica'
text.pointsize = 12
text.gravity = Magick::CenterGravity
state_midpoints.sort.each do |state_id, midpoint|
next unless state_to_vp_total[state_id]
cavs = state_id_to_cav(state_id, mod)
next if cavs == 0
text.annotate(img, 0, 0, midpoint.x - xsize/2, midpoint.y - ysize/2 + 2, "#{cavs}")
end
end
def call
{
"harshest" => 1.0,
"harsh" => 0.8,
"gentle" => 0.6,
"gentlest" => 0.4,
}.each do |level, num|
pixels = generate_map_image_pixels(suppression_color_map(num))
add_state_borders(pixels)
img = pixels_to_img(pixels)
add_suppression_labels(img, num)
write_image(img, "output/suppression_#{level}.png")
end
end
end
DrawSuppressionMap.new(*ARGV).call