基于自然地球形状文件的ascii艺术打印国家。
asciimap的Python项目详细描述
db .M"""bgd .g8"""bgd `7MMF'`7MMF' `7MMM. ,MMF' ;MM: ,MI "Y .dP' `M MM MM MMMb dPMM ,V^MM. `MMb. dM' ` MM MM M YM ,M MM ,6"Yb. `7MMpdMAo. ,M `MM `YMMNq. MM MM MM M Mb M' MM 8) MM MM `Wb AbmmmqMA . `MM MM. MM MM M YM.P' MM ,pm9MM MM M8 A' VML Mb dM `Mb. ,' MM MM M `YM' MM 8M MM MM ,AP .AMA. .AMMA.P"Ybmmd" `"bmmmd' .JMML..JMML. .JML. `' .JMML.`Moo9^Yo. MMbmmd' MM .JMML.
以ascii艺术形式打印国家/地区的终端应用程序
·-----· /...../ ´...../ |....| ,---· |.....--....| ´............· ·.........../ `........./ |.......| |,.......--· · |.........· |..........· ·--· ·-.........| |..-· `--.......· |...| `.......--· ·----· `......-.· United Kingdom ·.....-..· ·-----..........· |................· ·.................---· |...................| /...................,· ·-...................| `-..................· |................,· ,-....,....,------´ /....,´ `--´ ·-----´ ··
可以打印任何具有{“CD1}}”的国家,其中存在几何体(当前) 177个国家)。
依赖关系
要使asciimap
工作,需要gdal和gdal本身的python绑定
安装。我在将python绑定安装到
virtualenv,所以我建议安装系统包。
拱门
pacman -Sy gdal python-gdal
debian/ubuntu
apt-get update
apt-get install gdal-bin libgdal-dev python3-gdal
安装
pypi
pacman -Sy gdal python-gdal
apt-get update
apt-get install gdal-bin libgdal-dev python3-gdal
使用pip安装很简单:
sudo pip install asciimap
吉特
从主分支使用git安装:
git clone git@github.com:MaelStor/asciimap.git
cd asciimap
git checkout master
在用户空间中
在用户空间中安装:
pip install --user .
系统
在系统范围内安装:
sudo pip install .
用法
usage: asciimap [-h] [--fill FILL] [--empty EMPTY] [--outside OUTSIDE] [--height HEIGHT] [--width WIDTH] [--blur BLUR] [--method {full,f,dynamic,d,height,h,width,w}] [--surface SURFACE] [--negative] [--benchmark] [--stats] country Print countries in ASCII Art positional arguments: country Select country by ISO 3166-1 alpha-2 codes. For a complete list of ISO A2 codes use 'list' as argument optional arguments: -h, --help show this help message and exit --fill FILL, -f FILL Single character marking the edges of the land surface --empty EMPTY, -e EMPTY The character to use for the land surface --outside OUTSIDE, -o OUTSIDE Single character marking the outside surface --height HEIGHT, -i HEIGHT Height of the map as integer --width WIDTH, -w WIDTH Width of the map as integer --blur BLUR, -b BLUR Add blur to radius and inflate the surface by double value --method {full,f,dynamic,d,height,h,width,w}, -m {full,f,dynamic,d,height,h,width,w} Change rendering method --surface SURFACE, -s SURFACE Choose a surface by number or 'all' --negative, -n Print the negative --benchmark, -t Print execution times of methods along with the map. Can be give multiple times to increase verbosity. --stats, -x Print statistics List all countries and ISO 3166-1 alpha-2 codes with 'list'
示例
$ asciimap it
·-· ·---...· |.......----· ,----............| · ,---...............,-| ·----.................,´ · |.................../ |..................| ·...................| |......,...........| ·-...,´ `-..........· |./ `-........| ·´ `........-· |.........-· |..........| ·...........· `....Italy..· `...........· `-..........· `..........-· `-..........---· `--.........| `-........--· ,· `-.........-· ·-..· `-........--· |....· `....../ `--· |....· `..../ `-· |...| `..| |...| `..· ·..,· |..-· `´ |../ |./ |/ ´| ·-· ,---· ·· |..---....· ·--......| `---..| `-| ·
$ asciimap no
·-----· ·----· ,-· ,---· |,----------· ·-...---.....---/ `-..........,´ `-......,´ ·--· `-...| `· `--· ,--------· ,· ,-...,----..· ·-----.`....| `--· Norway../ `-----· ·-· ·´ ,-/ ,-./ /../ /../ /../ ,-..| /..,-· ,-..| ,-....· ,--.....| ,-........| ·...........· |...........| |...........| ·...........· |......,--´ ·....,´ ·--·
您可以打印带有负片过滤器的国家:
$ asciimap --surface 1 fr --negative
.........................................··..................................... ....................................... .................................... ....................................... ................................. ...................................... ................................ ...................................... .............................. ................................... . .......................... ....................... ........ ........................ ....................... ... ...................... ........................ ................... ........................ ............. ............... ..... ............ ...........· ............. ...........| ............. ...........| .............. ...........· .............. ............... .............. ................... . ............... .................... ................. ...................... ................... ....................... .................... ........................ France ..................... ......................... ..................... .......................... .................. .......................... ................. .......................... ................. .......................... ................. .......................... ................ .......................... ................. .......................... ................. .......................... ................. .......................... ................. .......................... ................ ......................... .............. ......................... .............. ........................ ............... ........................ .... ................. ......................... ................................. ............................ .................................. ................................ .. .................................. .......................................·----·...................................
或者如果希望显示边框:
$ asciimap --surface 1 --outside '.' fr
.........................................··..................................... .......................................·- ·.................................... .......................................| --·................................. ......................................´ ·................................ ......................................| -·.............................. ...................................,-- ·.,·.......................... .......................·........,-- ` -·........................ .......................·-·...,-- -·...................... ........................| --- --·................... ........................| -----·............. ...............,--·.....| ·............ ...........·--- ----- |............. ...........| ·............. ...........| |.............. ...........·--- |.............. ...............`--- , ·.............. ...................` |.\´............... ....................`- -·................. ......................` /................... .......................` /.................... ........................` France |..................... .........................` |..................... ..........................| --·.................. ..........................| ·................. ..........................| |................. ..........................| |................. ..........................| ·................ ..........................| |................. ..........................| |................. ..........................| |................. ..........................| |................. ..........................| ·................ .........................´ -·.............. .........................| ·.............. ........................´ ,--- ,´............... ........................· ,--´....`------´................. .........................`-- /................................. ............................`--- ,- |.................................. ................................`´..`-- ·.................................. .......................................·----·...................................
填料可以组合。如果你想用.
填充地表,
地面以外的一切都用~
和角落用^
使用:
$ asciimap nz --outside '~' --empty '.' --fill '^'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~··~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|·~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·.-·~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`..·~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~,-.......,´~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~,-........|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~/..........·~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~,-..........|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~´............·~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~|...........|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~·...........,·~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~·----.....,´~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~·---·~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
高级用法
使用“粘贴”并夸耀使用“模糊”的示例:
$ asciimap -b 0 jp -i 30 -w 30 | paste - <(asciimap -b 2.0 jp -i 30 -w 30)
· ·-· |· ´...-· |.-· · |.....---· /....--· /.........| ,-.,...,´ /...........· ´../ `./ ´............| ·-´ · |............| |............· ·-· |..........,´ |.| |........,´ |.| |.......| |.| |.......| ´..· ,--........· ·.· ·-..........| Japan |...Japan...· ·....· ,----...........| ,--....| /................| ´.......| ,-.................| ,-· |.......· /...................· ,--..--..,----´ /.................../ /-.,.| |./ ·.................../ ,-/ | \· ·´ |..............,---´ /.| |· ·............./ ·-..· · |........,--´ || ·......,´ |· |..../ · ·-../ `´
$ asciimap au --blur 0.1 --empty '.' --method full
·· ,-· || ,---...-----· ´..· /..........| |..| ,---· /...........| |...· /.....---............| |....--· /......................--· ´.......| ·· /..........................--· |........· |.`..............................----.........| /..............................................| /................................................-· ,----...................................................--· ,-----...........................................................· ,-..................................................................· ·-.....................................................................-· |........................................................................· ·..........................................................................-· |,..........................................................................· ·| |......................................Australia...........................· |`...........................................................................| ·............................................................................| `............................................................................· |...........................................................................· ·..........................................................................| `...........................,---..........................................| |...................,-----´ `----.....................................· |................,-´ `......,...........................,´ /........,-------´ `...,´ |........................./ ·--....,-´ `-´ /-......................../ `--´ ·· `....................../ `....................| `...................| `--......,.....,---· `----´ `---´ ·· ,-· |---..· ·...,´ ·-·
有时一个国家有不止一个地表(或者更精确地说:多边形) 定义,什么扭曲或只显示感兴趣表面的几个像素 同时打印所有曲面时:
$ asciimap --surface all --method full ru --fill "'"
· · · · ,· · ,-..· · · /....| · ´.....| · · |......---· | · | |.........| |· · | ´...........--..-· · · |................| · ·· · |.................--· · · ·\ ·--.· |....................`| · · |...| |.....................| · · ·-.....`......................| · | |............................| |--.............................| |...........................,-..· |.............Russia.......| |/ ´...........................· · |........................,-´ |.......................| · |.......................| | ·-......................· | |......,.............| | · ´....../ |,...........| | |.....| · |........,..· · ·...,.· ·....,...| |.| |.| · `.,| |..| |.| ·.· | · ·.,· |.| | · · ·.| | `| |· | ·.| | · |· · · | · ·· · ·
为了克服这种偏差,您可以只渲染大的陆地表面,例如使用:
$ asciimap --surface 1 --method height ru --fill "'"
·-· ,---...--------· ,---------.............,--· ,---......................| ·-----...........................--· ,---· ,· ,--· · |,..................................`.....-----..---· ·--· /..| ´| ,---| |.................................................| |...------· ·-....· |.`.....`...................................................--· ,-------...........---· ,---· `....| ·..............................................................`.......................`.....· ·· ·-------· ,---· \...| |............................................................................................---------· |.-------· |.......---· ·-· ,--· ,-----.....--· |..-· |......................................................................................................--.........| ·....,--....· `| ,--....`..............`..| /..................................................................................................................| |..| `--´ ,· |---.........................| /...................................................................................................................| |...· ·-..`..............................`...................................................................................................................,· |...| ,--......................................................................................................................................................| ·....---..........................................................................................................................................................· |...........................................................................................................................................,...,-...........,----· /..........................................................................Russia.........................................................,-´ |,´ |.......,-´ ·-........................................................................................................................................,´ · ·-.,-----´ |...........................................................................................................................,---------../ ·---´ ·-..........................................................................................................................,´ `´ /./ ·.........................................................................................................................,´ ,-.| |......................................................................................................................./ ·-....-· ·--..........................................,........................................................................,´ |.....,· |.....................................,--´ `......,...............................................................| ·...../ ·-...............................,---´ `----´ |...............................................................· |.../ |.............................| ·..............................................,-----............---· |../ ·--..................,-........| `.....................,......................| `...............· |./ `...............,´ `------.· `----.........,...../ `--...................· |.............| ·´ `---.........,´ · `-....,-´ `---| `-----......,-.,../ ·.............| `......./ `--´ · `----´ · `´ `--..........| |.....| |..,-.....· |......· ·-´ |.../ /........· ´.../ /.........-· |../ ·-........./ · /../ `--.....| |`../ `----.· ·--´ `-\ ·
或
$ asciimap --surface 1 --method width --height 20 ru --fill "'"
·-· ,-------...-· · ,--.............--------· ´.· ·--.........................· ,---------· ·--· ,· |.| |............................`...........-------· ,---· |..--· · ,------..`..| |................................................`....| ·.| ·-.`.............`......................................................· |.---.............................................................,..,....,-´ /...................................Russia.....................,../ `| `--´ ·..........................................................,---´ `´ | ·-.......................................................,´ ,-| |...............,-----.,..............................| ´..· ·-............./ · `..........,...........,--.....· ·./ `-....,-----´ `--...,-.| `---...,../ `.....-· · `..| `-´ `· `-´ `´ `.,..| |.| · |.· ´...· |/ ·--´ ·-· ·
要找到正确的表面,你必须尝试一下。我在做一个 更好的解决方案。
性能
渲染和打印时间取决于生成的贴图的大小。致使
用40x80 (h x w)
打印一个国家通常需要0.1 - 0.3
两核系统上的秒数。实现渲染以使用并行进程
减少了多核系统的计算时间。使用inbuild基准
系统需要安装“yappi”。这不是一个严格的依赖,因为它只是
用于开发。打印“yappi”结果,例如使用
$ asciimap de --benchmark
统计
配置和统计信息以--stats
(或-x
)沿
结果地图和基准测试结果。
$ asciimap ca -x
·----------------· ,-------...........,-´ ·---.| |.....,---´ `-..--· ,-.....| ·· ·· `´ |`....,--· ·-· ·-----´ ·· ·--· ,· ·--· ·· ·--· · ·-· |---------· ,-----· |.--´ ·..../ |-· · · ,· · ·-· || ·--· ,--· `--´ ·.,--.--.`..· ·-· || ·...`....----· · |.......· /-.· `--...,----..----· ·· ,--------· ,-· ·------....-· ·--/ |.-· |.| `--....-· |.---..........`...---.| |..| || |...-· |..· `....| |.......................-----....-----..--......· `--· · |...---· |................................................· /...| `-· |.............................................,-´ ·· ·----....· |...........................................,´ ·-· ,· `-...-· |..........................................· ·· `-´ · |.....................................Canada · ·---· ·-..,....................................· |....--· `´ `-..................................| |......| ,· `..................................· ·.......· /..· `..................................· |.......`....· `..................................---· |............| |.....................................----· /..............-· · ·.........................................| ´.................-· `.........................................· |...................· \.........................................· |.................,-| · |,........................................`...........,--.,-´ | · |,---------------------------.....................,| · /| · `-----............../ ·-· ·----· `-...........| || · `..........· ·-· · · |....,---´ ·-· |..,´ · ·-´ MapConfig max_height: 40 height: None max_width: 80 width: None fill_char: '*' no_char: '.' outside_char: ' ' blur: 0.0 method: 'dynamic' surface: 'all' is_negative: False PrinterConfig fill_char: '*' no_char: '.' outside_char: ' ' is_negative: False is_unicode: False padding: (1, 0, 1, 0) max_width: 80 max_height: 40 RenderConfig name: 'Canada' geom: <osgeo.ogr.Geometry; proxy of <Swig Object of type 'OGRGeometryShadow *' at 0x7f95b7a52c60> > centroid: (-98.14238137209722, 61.46907614534891) lowest_lon: -140.99778 lowest_lat: 41.675105088867326 highest_lon: -52.64809872090421 highest_lat: 83.23324 lat_diff: 41.55813491113267 lon_diff: 88.34968127909579 worker_count: 4 h_res: 1.1043710159886975 w_res: 1.1043710159886975 max_height: 38 max_width: 80