-
Notifications
You must be signed in to change notification settings - Fork 2
/
mapgen.rb
executable file
·123 lines (97 loc) · 2.77 KB
/
mapgen.rb
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env ruby
# mapgen.rb
# 以下の設定により衛星写真とレーダーの白地図を作成、ターミナルに出力
# それをスクリプトにコピペ
# 願わくば間隔空けず連続実行することなかれ
require 'open-uri'
require 'base64'
require 'rmagick'
#### 設定
# これらをスクリプトにコピペ
# 衛星写真座標
# satmap-key.pngを参照
# 下記は本州、首都圏を中心に
$satxa = 27
$satxb = 29
$satya = 11
$satyb = 13
# レーダー座標
# radmap-key.pngを参照
# 下記は首都圏
$radxa = 226
$radxb = 227
$radya = 100
$radyb = 101
# 台風用衛星写真座標
# 大概変更不要
$typhxa = 12
$typhxb = 15
$typhya = 5
$typhyb = 8
####
## satmap
$satmaplist = Magick::ImageList.new
for i in $satxa..$satxb
ilist = Magick::ImageList.new
for j in $satya..$satyb
url = "https://www.jma.go.jp/tile/jma/sat/5/#{i}/#{j}.png"
png = Magick::Image.from_blob(URI.open(url).read) do |img|
img.format = 'PNG'
img.background_color = 'transparent'
end
img = png[0].modulate(1.0,1.0,1.0).to_blob
# ↑ modulate => 明度・彩度・色相を変更(1.0 == 100% == 変更なし)
list = Magick::ImageList.new
ilist.from_blob(img)
ilist += list
end
row = ilist.append(true)
$satmaplist.push(row)
end
satmap = $satmaplist.append(false)
satmap.write("./satmap-test.png")
puts "satmap64 = \"#{Base64.encode64(satmap.to_blob).strip}\""
puts
## radmap
def splitmap(img) # 6144x5888 24x23 (256x256px)
grid = Magick::ImageList.new
for x in ($radxa-213)..($radxb-213)
rowlist = Magick::ImageList.new
for y in ($radya-90)..($radyb-90)
tile = img.crop(Magick::NorthWestGravity,x*256,y*256,256,256,true)
tile.background_color = 'transparent'
list = Magick::ImageList.new
rowlist.from_blob(tile.to_blob)
rowlist += list
end
row = rowlist.append(true)
grid.push(row)
end
return grid.append(false)
end
radmap = splitmap(Magick::Image.read("./radmap.png")[0])
radmap.write("./radmap-dark-test.png")
radmap.negate.write("./radmap-light-test.png")
puts "radmap64 = \"#{Base64.encode64(radmap.to_blob).strip}\""
## typhmap
$typhmaplist = Magick::ImageList.new
for i in $typhxa..$typhxb
ilist = Magick::ImageList.new
for j in $typhya..$typhyb
url = "https://www.jma.go.jp/tile/jma/sat/4/#{i}/#{j}.png"
png = Magick::Image.from_blob(URI.open(url).read) do |img|
img.format = 'PNG'
img.background_color = 'transparent'
end
img = png[0].modulate(1.0,1.0,1.0).to_blob
# ↑ modulate => 明度・彩度・色相を変更(1.0 == 100% == 変更なし)
list = Magick::ImageList.new
ilist.from_blob(img)
ilist += list
end
row = ilist.append(true)
$typhmaplist.push(row)
end
typhmap = $typhmaplist.append(false)
typhmap.write(BASEMAP)
puts "$typhmap64 = \"#{Base64.encode64(typhmap.to_blob).strip}\""