Skip to main content

view color images and 3d scientific visualization inside an ssh terminal (screenshots using putty ssh terminal included)

Project description

################################################################################
this is a moderately complex python3.0 script for performing fast, high quality
graphics -> ascii conversions. it relies on py3to2 in order to use PIL &
numpy extension modules. for performance, portions of it have been inlined w/
direct C code using scipy.weave.
asciiporn can easily render & display megapixel images on a 1ghz 500mb machine.

asciiporn's main purpose is to provide ascii-converted, high-quality,
color-3d plots within an interactive python txt terminal.
however, its fast txt-rendering engine can also b used for viewing image files.
screenshots of both applications r included w/ this distribution.

if something fails, try updating ur install of py3to2 to the latest version @:
http://pypi.python.org/pypi/py3to2

how to enable 256 color in putty: http://www.emacswiki.org/emacs/PuTTY#toc2
how to enable 256 color in xterm: http://www.frexx.de/xterm-256-notes/

asciiporn is hard-coded to use lucida-console font, but courier font will work
as well. the screenshots show putty ssh w/ lucida-console 5pt.

AUTHOR:
kai zhu
kaizhu@ugcs.caltech.edu

REQUIREMENTS:
- posix os
- Python Imaging Library http://www.pythonware.com/products/pil
- numpy http://www.scipy.org/Download

PSEUDOMETHOD:
asciiporn uses ".." syntax notation for pseudomethods
goto: http://pypi.python.org/pypi/pseudomethod
for more details about this feature

API:
asciiporn module:
- img2plaintxt - converts image file to portable plain txt
u can copy & paste in documents
- img2txt - converts image to high-quality colorized txt
for display on terminals supporting 256 color (putty, xterm...)
- plot - plot multiple 2d functions
- plot3d - plots a 3d function that takes in 2 parameters

INSTALL:
python setup.py build
python setup.py install
python setup.py dev --quicktest

################################################################################
PLOT USAGE:

2d plots take 2 main arguments:
y - a list of functions to plot
trange - t domain

>>> import asciiporn, numpy
>>> asciiporn.plot(
... ft = [ # list of single argument functions
numpy.cos,
numpy.sin,
lambda t: numpy.sin(t + 0.25),
],
... tmin = 0.0, tmax = 7.0, # range of t
... )



SIDEVIEW Y: Z 0 to 2 Y -0.99983900113 to 1.0 T 0.0 to 7.0 MIN MAX
l?*~_-----_>cC}lTl{7Tx_--------------------------------------------_+*Tll'*+_---
| T, ,r',*l '_ ), .( `-_
| a_ / )_ \_ ,* ,(
| ,C ~C `. , ) )
| ) > \ \ \ / / (
| / / \ '_ ^ ' _^ '
| ( ' '_ `_ ) ' ' ,'
|r _' `c '_ ,' ,' ,
( ' _ c ` , ,' ,
| ' `c c `_ , , .
|' `c _ ` , ,' +
----------------`---------------L-`-------------- --.--------------,'-+--------
| _ c `_ . ,' +
| _ `C ` . ,' +
| c . . ,
| `C , c , , )
| , . ?c ) ) /
| x t . / < /
| \ \ \ ( / _*
| '_ '_ ;C ,' ,'
| x (%) x x _x
| '< _>' ?x_'C >'_r'
|------------------------------`*<____>r------`*<{jy_yj1+*'---------------------



3d plots have an extra argument:
zrange - z domain

>>> import asciiporn, numpy
>>> asciiporn.plot3d(
... y = lambda t, z: numpy.sin(t + t*z), # y is now a fnc taking 2 args (t, z)
... tmin = 0.0, tmax = 7.0, # range of t
... zmin = 0.0, zmax = 0.25, # range of z
... )



SIDEVIEW Y: Z 0.0 to 0.25 Y -0.999 to 0.9999 T 0.0 to 7.0 MIN MAX
|---------`WDHbPgHHbmW_---------------------------------------------_mH&&EHH&&EH
| q88'' 'b&EHD_ _mdHH&&QmH&&dm
| _M&W` NEHHbW_ s8&mHH8&gHF8&dm
| _HHl #HHb&&p `=bM@mjjD@d@]hIdH
| _HF' ]Hb&&IL j]kM@m&ahMgk]uHB'
| _bg ]b&&IHm` sdkAUh$kkUP$F]l+'
| `8h 3&&IHm#` ?hm]k[hdFElP]F%nl
| HC d&Imm&8` (UhhEk1{jJk[1j]L`
| M' 8dHb&&d_ _dPUR]k{hRF}P[6i'
|j' mHm&&dH` _]ahUg]k[3B}jCf]
_C `Hb&&dHH_ Ak}1U%]6UC&jFh+`
'----------------- ---------'b&&mmm&_------ -------------s$k4hU%]]CnjFjT`-------
| 3&&mmH@@, cI$]kppA}}nhB]J`
| 8&$mH&&8_ -Dhd]dUhA]}{3&J'
| `gmHH8&dH` _aMM$kaUh%]]huj
| `mHH&&dHH_ `jg@Qd&4MKd}aPl`
| 'HH8@HHH&_ _]jgDMdk}UUdk}T`
| 'H&8HHH&&, @mHaDMdkk@@HA*
| '&&dHH&&dL q8mmb&#dkE@@d'
| ?&EDH&&dHH_ `g&Wmmb&8dH$&@'
| ?dHH&&EHH&p``mb&8mmD8&dHbl`
| `WH&&EHH&&8HHb&EHHD&8dF'
|--------------------------------------'NMEHH&&EHHb&EHHbMPl---------------------

TOPVIEW Z: Z 0.0 to 0.25 (top to bottom) Y -0.9999 to 0.9999 T 0.0 to 7.0
DOGKz1(7Lx\:,-'` `._~>r?;tfVne6H MQpZaV}oTY?+(,!'` `'-_>+|/Cc[]KPRg 8REnVSt7
DOGKX3(7/vi:_-` `-_~iv/YcS{aZqm &8qI4yzts7r~i'-` `-'i~r7stjy4Iq8& dqEa{jtYL
DAG5X3cY/vi~_.` `'-,:|xJT=3y4U9 Wm0EXnFTY?\(_!.` `'!,:\l^)Fn3U9mN m%Za{j=Y?x
DAZ5{jcY?r>~_.` `''!(+lsCf}neR8 $gRI4yz=slx*i'.' `'-_(+rYT2[]GO6D D9U5X3=T?r*
DAZa{jt;?r>!'.` `._~i|/YcoV5GOd BH9GXnF)Y?\:_-'` `.!i~vLstj{3PhbN HqE][fCsx*i
DAZa{jt;l|(!'.` `._~irL7=j{4U9 @D6OK][oT7r*>'.' `'-_(\|Y)FnXGqd# bAZa[ft;l+(~
mqEaVoCsl|(,-' '.,: J)2}yeR8 &bhP3{jts?\:,-'` `.'i*r7Jo[VawmW OG5XSc;?r>!_
mqEnVoCs^+:,-' `'-!(+^;tSkuGOd WmAeV[oTYr*>'.` `'!,(vL^)fy4PhQ 8U4z1cY?ri!'.
mqEnkS)Jx*:_-' `'-~>|l7(j{50h gRZK{jtsl\:,!'` '-'>*|YT2k3U9H Hqwy}27/v\:'.'
mqeukS)Lx*~_.` `.'~|r/)F1ywqH $d9U3}2TY|*>'-` `.!,:v7J=zXGO6W dOZu[fCLv\:,.``
mqeu[fTLv\~'.` `._:*xLtfkueOm #%0EVfcslx:,!'` `-_(+|^)S{KZRg 9IKVSt;x*(,-`
mReu[fT/v\!'.` '-_(+^sco{5Gh @DhP5uF(Y?\>'-' `'!,:vLJ=z]eAHB Hqeu1FTL|i~'.`
mRe][27/ri!''` `'-,>|l;=3z4U8 $89e1noC/r*i!.` `._(+|Ytj{5w%D OZaV2)Jxi~_.`
mRP]}27?ri!-'` `''!ir?72}]PRd #H0a]zt^Lv:_-' `'!i~x7J2}Xeh8 8UKXjts^+:_.` `
dRP]}FY?|>,-' `.'! LTSknZA D%I5{ST/|*>!.` `.'(\?;)zyawH# dAPy1FYl|>,-' '
d6Py1F;l|>,-' `._~*xJCjXKI9 $8hGX}oslv:,-' `'!,*r/Cok3IhD 9InkfC/ri~-'` '-
d6wy1=;l+(_.` `-_:+l;c1yw68 #HAKyftY|+>_.` `.'>\L^tjVGOm 86w{oc;x\:_.` `._
d6wz3=s^+(_.` '-,(r?7=[uEA DRZ3kF(7x~i!'` '!,:r/T2n4ZRQ dAEu3=7?+(,-` `'_~
d6wz3(s^*(_.` `''!>vLT2V5G% $8qUV[=J?\(_-` `.'>*?^tjuGAH# p04zSCJxi~'.` '-~i
d6wz3(sx*:'.` `''!ixJ)fXKUh NdAGyft^|*>'.` `-,:v/C2n1ZRQ qe]}(Yl+:_.` `._(+
d04XjcJx\:''` `.'~\^stoywRH W6wKkFTYx:,!' `''>*|^tfya9b& 9GaVST/ri,-' `.'~*x
d04XjcJv\~-'` `._:*lY(3uEAm gpI3[=Jl+(_-` `.,:vlT2n3I6W m6wzj(Jx\:''` `''!>vL
d04XocLv\~-' `-,(+/7F}aG9 @d9GVj);?~i!.` '-i~r/)jyK0d& 8Gakf)?|>!.` '-,(+/T



asciiporn can also plot user-supplied (y,t) datapoint pairs:

>>> import asciiporn, numpy
>>> t = numpy.arange(1000) # create t coord datapoints
>>> y = numpy.sin( 0.01*t ) # create y coord datapoints
>>> yt = list(zip( y, t )) # create (y,t) datapoint pairs
>>> asciiporn.plot( yt = yt )



SIDEVIEW Y: Z 0 to 0 Y -0.99999 to 0.99999 T 0.0 to 999.0 MIN MAX
|--------_<?l'*c-------------------------------------------->*'lt<--------------
| >' \_ ~' '_
| / `c / ,
| ^ ` / >
| / v v
| / ` , c
| , ' `
| Y ^ | ' / ,
|/ - ,
| \ `
'----------- ------------L----------- ------------/------------------------:----
| s
| ^ `
| l ^ | c / >
| ` , c
| ^ `
| \ '
| Y _'
| \ _'
| \_ .'
|---------------------------------`>_,_.*---------------------------------------



################################################################################
IMAGE USAGE:

in this example, u'll b loading the image file included w/ this distribution,
"mario.jpg". its a fairly large image, so u prolly want to scale it down
to 0.5 (or less):
>>> colortxt = asciiporn.img2txt("mario.jpg", scale = 0.5)
>>> print( colortxt )

... beautiful color image appears ^_-

>>> plaintxt = asciiporn.img2plaintxt("mario.jpg", scale = 0.5)
>>> print( plaintxt )

... rather plain b/w img -_-, but u can copy & paste in documents ...



__*^>_` ~+| ~rL!!_ ?*_> r '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
^M`__| |`ttY>r_t-LLkoi^ ( ' +@@@@@@@@@@@@@@@@M@@$lh@3MM@@@@@@@@@@@@@@@@@@@@@
^g@$@&_`^'t|x!lt'T7`\^]_ gp_ `rwM@MMMMP@M@@@@@R =/n7_`|!I@@@@@@@@@@@@@@@@@@@@
`@@@@@B ' ` !'^'?''^=&g, _@u ^SJE^?{L-|+SF$tJsA#N&@ajqJnr}@@@@@@@@@@@@@@@@@@
`@@@@@B ``` ` | ^ 1@$In TF) .=kL'> '^{?^ Lt'yC d@&M@g@2@@@@@@@@@@@@@@@@@@@
_`MN@Qh- ^ > _ `|`v4$g&gg@J^t[MR~ / Y7EXE,-> Yjggg&m@@@$#&@@@@@@@@@@@@@@@@@@
`' `!'' '` (_&@#@@@@@jMmK4g(^ `r~ {' ^i[g@@@@@@$@@@$99@@@@@@@@@@@@@@@@@
`'~ J\+ >i3@q@N&g@p@&}@VMw?^`>C~J' g@&@W@@@@$&@$@@$6|@M@@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( rr ~r7 i`_ ',^
`$@W@&$zJ-^(` ```s Xj`_j>^-!Txt7=X!)`k?L+-i >_i ) ` |`_`^ 'i^(x !! ^!
_&##M@&'^i' `'_j')`+tr+|7,yLrbJC{|TL^C^ J ^' `L`^ +?_v_ C cur
3$$MM@->SC x*_>x )|rV^^l!_?kI{{[_y!~ { ` s' '!_^Js> `t{\_``
B `[&&&z\o^Yx?(-{ '{'s*|-cn=7)T&l=s=SrL _!l`+r `_`>l+,`Y `_^`!_
$L @}Wi >7^__iY> +r ?`~ !_=^({nL^j\ T ` ` ^ _` +~ L '! ttt_~i|!X`^i\]
@@ ~&LifL(*'=! \V_{ct7{+c(Jv_'>v'L i _ i c`\{^ v ` \^ ^ s,_`^L



actually, the plaintxt prolly won't look well when pasted,
b/c most document readers invert the color:
>>> plaintxt = asciiporn.img2plaintxt('mario.jpg', scale = 0.5, invert = True)
>>> print( plaintxt )

... b/w img w/ colors inverted. may look funny now :/
but it'll b normal when pasted in document

################################################################################
RECENT CHANGELOG:
20080121: removed py3to2 requirement
20090103
rewrote 3d plotter
fixed more 64bit issues
20081123
fixed bug where 64bit gets truncated to 32 on 32bit machine
256 color support
20081119
fixed bugs in setup.py

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page