日本地図の塗り分け
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2021/07/23 00:51 UTC 版)
「Processing」の記事における「日本地図の塗り分け」の解説
ウィキメディアのSVG形式の日本地図の白地図を読み込み、Prefectures という配列に記述された番号の県のみ塗り分けるプログラム。英語版の例のように地図データが各県ごとに name を持っていれば県名で指定することも可能である。 PShape japan;float map_scale=0.25;int square_len=512;int [] Prefectures={2,3,5,7,11,13,17,19,23,29,31,37,41,43}; // Prime numbersvoid setup() { japan=loadShape("http://upload.wikimedia.org/wikipedia/commons/5/56/Blank_map_of_Japan.svg"); size(square_len,square_len); smooth(); noLoop();}void draw() { background(color(0, 0, 255)); // blue japan.disableStyle(); japan.getChild("ground").getChild(0).scale(map_scale); fill(color(255, 255, 0)); // yellow shape(japan.getChild("ground").getChild(0), square_len * map_scale, square_len * map_scale); prefecturesColoring(japan ,Prefectures , color(255, 0, 255), map_scale); // magenta saveFrame("map output.png");}void prefecturesColoring(PShape nation, int[] prefectures, int c, float n){ for (int i=0; i < prefectures.length; i++) { PShape prefecture=nation.getChild("ground").getChild(0).getChild(prefectures[i]); prefecture.disableStyle(); // Disable the colors found in the SVG file prefecture.scale(n); fill(c); // Set our own coloring noStroke(); shape(prefecture, square_len * map_scale, square_len * map_scale); // Draw a single prefecture }}
※この「日本地図の塗り分け」の解説は、「Processing」の解説の一部です。
「日本地図の塗り分け」を含む「Processing」の記事については、「Processing」の概要を参照ください。
- 日本地図の塗り分けのページへのリンク