Introduction: Graphics in a Text World.
Sometimes when sitting at a text only terminal, It would be nice to see some kind of picture even if it was crude. For example, you just got an email saying you have to look at this picture! Here you will get a chance to experiment with pictures from the command line. Thought not perfect, you may have to stand back a bit to get the full effect of the pictures. Also too, if you want to put pictures on the text only lcd signs, this is a good way to convert the pictures.
Note: the higher screen resolution you are using will improve the pictures.
Note: the higher screen resolution you are using will improve the pictures.
Step 1: Get Some Software.
You will need a jpg to ascii converter, image converter, and a page grabber.
For Ubuntu based machines:
sudo apt-get install jp2a imagemagick curl wget
For Ubuntu based machines:
sudo apt-get install jp2a imagemagick curl wget
Step 2: Conversion to Jpg Format.
Someone just sent me the robot picture which is in ,png format.I need a jpg format. No problem...
$ convert robot.png robot.jpg
Now you want to display the picture.
$ jp2a -b --colors rogot.jpg
it is that simple.
$ convert robot.png robot.jpg
Now you want to display the picture.
$ jp2a -b --colors rogot.jpg
it is that simple.
Step 3: Getting Pictures From the Web.
This is a little more tricky. For now we will do it the crude way. Now someone has said you need to look at a picture at www.cnn.com.
Lets get all the picture names from the from page of www.cnn.com and save the data.
$ curl www.cnn.com | grep ".jpg" > cnn.txt
$ nano cnn.txt
You will want to pick out the important file name of the picture.you want to use
$ wget http://i2.cdn.turner.com/cnn/2011/images/10/21/t1main.1228.libya.celeb.afp.gi.jpg
Display the pic.
$ jp2a -b --colors t1main.1228.libya.celeb.afp.gi.jpg
or
$ jp2a -b --colors http://i2.cdn.turner.com/cnn/2011/images/10/21/t1main.1228.libya.celeb.afp.gi.jpg
I probably did not pick out the best picture to display, but that is how it goes sometimes. Better than nothing.
--------------------------------------------------------------------------
$ curl www.cnn.com | grep ".jpg" > cnn.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 107k 100 107k 0 0 192k 0 --:--:-- --:--:-- --:--:-- 270k
$ nano cnn.txt
$ vim cnn.txt
$ wget http://i2.cdn.turner.com/cnn/2011/images/10/21/t1main.1228.libya.celeb.afp.gi.jpg
--2011-10-21 12:02:29-- http://i2.cdn.turner.com/cnn/2011/images/10/21/t1main.1228.libya.celeb.afp.gi.jpg
Resolving i2.cdn.turner.com... 8.26.219.254, 205.128.65.126, 204.160.102.126
Connecting to i2.cdn.turner.com|8.26.219.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17983 (18K) [image/jpeg]
Saving to: `t1main.1228.libya.celeb.afp.gi.jpg'
100%[===================================================================================>] 17,983 --.-K/s in 0.04s
2011-10-21 12:02:29 (429 KB/s) - `t1main.1228.libya.celeb.afp.gi.jpg' saved [17983/17983]
Lets get all the picture names from the from page of www.cnn.com and save the data.
$ curl www.cnn.com | grep ".jpg" > cnn.txt
$ nano cnn.txt
You will want to pick out the important file name of the picture.you want to use
$ wget http://i2.cdn.turner.com/cnn/2011/images/10/21/t1main.1228.libya.celeb.afp.gi.jpg
Display the pic.
$ jp2a -b --colors t1main.1228.libya.celeb.afp.gi.jpg
or
$ jp2a -b --colors http://i2.cdn.turner.com/cnn/2011/images/10/21/t1main.1228.libya.celeb.afp.gi.jpg
I probably did not pick out the best picture to display, but that is how it goes sometimes. Better than nothing.
--------------------------------------------------------------------------
$ curl www.cnn.com | grep ".jpg" > cnn.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 107k 100 107k 0 0 192k 0 --:--:-- --:--:-- --:--:-- 270k
$ nano cnn.txt
$ vim cnn.txt
$ wget http://i2.cdn.turner.com/cnn/2011/images/10/21/t1main.1228.libya.celeb.afp.gi.jpg
--2011-10-21 12:02:29-- http://i2.cdn.turner.com/cnn/2011/images/10/21/t1main.1228.libya.celeb.afp.gi.jpg
Resolving i2.cdn.turner.com... 8.26.219.254, 205.128.65.126, 204.160.102.126
Connecting to i2.cdn.turner.com|8.26.219.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 17983 (18K) [image/jpeg]
Saving to: `t1main.1228.libya.celeb.afp.gi.jpg'
100%[===================================================================================>] 17,983 --.-K/s in 0.04s
2011-10-21 12:02:29 (429 KB/s) - `t1main.1228.libya.celeb.afp.gi.jpg' saved [17983/17983]
Step 4: Cartoons.
Sometimes solid picture cartoons come out better. Just depends...
Step 5: Screen Size Benefit.
As I said the bigger the screen, clarity should get better.
Step 6: Invert It.
Sometimes using the invert option (-i) can increase clarity. If you want to print it out, lots of ink will be saved also.
$ jp2a -b -i abe.jpg
$ _
$ jp2a -b -i abe.jpg
$ _
Step 7: Web Page Graphic.
Create a web page graphic with:
$ jp2a --color --html --fill --background=light hs.jpg --output=hs.html
to display:
$firefox hs.html
$ jp2a --color --html --fill --background=light hs.jpg --output=hs.html
to display:
$firefox hs.html
Step 8: Video Using Text Only.
Step 9: Yaicp.
Yet another image conversion program.
Get the software:
$ sudo apt-get install caca-utils
Get the pic
getpic::
[code]
DAY=$(date +"%m%d%y%H%M%S")
picfn="pic$DAY.png"
# echo $picfn
wget http://radar.weather.gov/ridge/Thumbs/HGX.png -O hgx$DAY.png
[/code]
Convert
$ img2txt -W 80 -f utf8 img2txt -W 80 -H 25 -f utf8 hgx110711051503.png > hgx110711051503.txt
Display
$ cat hgx110711051503.txt
Get the software:
$ sudo apt-get install caca-utils
Get the pic
getpic::
[code]
DAY=$(date +"%m%d%y%H%M%S")
picfn="pic$DAY.png"
# echo $picfn
wget http://radar.weather.gov/ridge/Thumbs/HGX.png -O hgx$DAY.png
[/code]
Convert
$ img2txt -W 80 -f utf8 img2txt -W 80 -H 25 -f utf8 hgx110711051503.png > hgx110711051503.txt
Display
$ cat hgx110711051503.txt
Step 10: Ascii Analog Clock.
Linux Analog clock (try at your own risk)
Compile with gcc aclock-unix-curses.c -o aclock -lcurses -lm
[code]
/*
* aclock - ascii clock for UNIX Console
Compile with gcc aclock-unix-curses.c -o aclock -lcurses -lm
[code]
/*
* aclock - ascii clock for UNIX Console
*
* Copyright (c) 2002 Antoni Sawicki <tenox@tenox.tc>
* Version 1.8 (unix-curses); Dublin, June 2002
*
* Compilation: cc aclock-unix-curses.c -o aclock -lcurses -lm
* Debian compilation: gcc clock.c -o clock -lcurses -lm
*
*/
#include <unistd.h>
#include <curses.h>
#include <math.h>
#include <time.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
void draw_circle(int hand_max, int sYcen, int sXcen, int FontHW){
int x,y,r;
char c;
for(r=0;r<60;r++){
x=cos(r*M_PI/180*6)*hand_max*FontHW+sXcen;
y=sin(r*M_PI/180*6)*hand_max+sYcen;
switch (r) {
case 0:
case 5:
case 10:
case 15:
case 20:
case 25:
case 30:
case 35:
case 40:
case 45:
case 50:
case 55:
c='o';
break;
default:
c='.';
break;
}
mvaddch(y,x,c);
}
}
void draw_hand(int minute, int hlenght, char c, int sXcen, int sYcen, int FontHW){
int x,y,n;
float r=(minute-15)*(M_PI/180)*6;
for(n=1; n<hlenght; n++){
x=cos(r)*n*FontHW+sXcen;
y=sin(r)*n+sYcen;
mvaddch(y,x,c);
}
}
int main(void){
char INFO[]="Copyright (c) 2002 by Antek Sawicki <tenox@tenox.tc>\n"
"Version 1.8; Dublin, June 2002\n";
char digital_time[15];
int FontHW = 2;
int sXmax, sYmax, smax, hand_max, sXcen, sYcen;
time_t t;
struct tm *ltime;
initscr();
while(1){
time(&t);
ltime=localtime(&t);
sXmax = COLS;
sYmax = LINES;
if(sXmax/2<=sYmax)
smax=sXmax/2;
else
smax=sYmax;
hand_max = (smax/2)-1;
sXcen = sXmax/2;
sYcen = sYmax/2;
erase();
draw_circle(hand_max, sYcen, sXcen, FontHW);
draw_hand((ltime->tm_hour*5)+(ltime->tm_min/10), 2*hand_max/3, 'h', sXcen, sYcen, FontHW);
draw_hand(ltime->tm_min, hand_max-2, 'm', sXcen, sYcen, FontHW);
draw_hand(ltime->tm_sec, hand_max-1, '.', sXcen, sYcen, FontHW);
mvaddstr(sYmax/4, sXcen-5, ".:ACLOCK:.");
mvprintw(4*sYmax/5, sXcen-5, "[%02d:%02d:%02d]", ltime->tm_hour, ltime->tm_min, ltime->tm_sec);
refresh();
sleep(1);
}
endwin();
return 0;
}
[/clock]
--------------------------------
Another clock: http://webonastick.com/vtclock/
Step 11: Yet Another Command Line Clock
You can get tty-clock at: https://github.com/xorg62/tty-clock
Step 12: Couple of New Year's Scripts.
Countdown clock:
Must be run on a linux box with figlet installed.
$ sudo apt-get update
$ sudo apt-get install figlet
Code:
$ while [[ $(date +%Y) -ne 2012 ]];do figlet $(($(date -d 2012-01-01 +%s)-$(date +%s)));sleep 1;clear;done;figlet 'Happy New Year!'
-----------------------------------------------------------------
Fireworks:
Fireworks.sh
[code]
#!/bin/bash
rows=$(tput lines)
cols=$(tput cols)
colors=(red green blue purple cyan yellow brown)
lock_file=
lock_file_base=/tmp/$(basename $0 .sh)
multiple=0
if [[ "$1" ]]; then
nsingle=$1
shift
else
nsingle=10
fi
if [[ "$1" ]]; then
nmultiple=$1
shift
if [[ $nmultiple -gt 8 ]]; then nmultiple=8; fi
else
nmultiple=6
fi
function colorstr()
{
local row=$1
local col=$2
local color=$3
local v
case "$color" in
red) v=31;;
green) v=34;;
blue) v=32;;
purple) v=35;;
cyan) v=36;;
yellow) v=33;;
brown) v=33;;
white) v=37;;
*) v=;;
esac
shift 3
if [[ $multiple -ne 0 ]]; then
touch $lock_file
while [[ $(ls $lock_file_base.* 2>/dev/null | head -n 1) != $lock_file ]]
do
sleep 0.05
done
fi
tput cup $row $col
echo -n -e "\e["$v"m"
set -f
echo -n $*
set +f
if [[ $multiple -ne 0 ]]; then
rm -f $lock_file
fi
}
function center_colorstr()
{
local row=$1
local color=$2
shift 2
local s="$*"
local slen=${#s}
colorstr $row $(((cols / 2) - (slen / 2))) $color "$s"
}
function fireworks()
{
local row=$((rows - 1))
local col=$(((RANDOM % (cols / 2)) + (cols / 4)))
local height=$((RANDOM % rows - 2))
local slant
local h
local color1=${colors[$((RANDOM % ${#colors[*]}))]}
local color2=${colors[$((RANDOM % ${#colors[*]}))]}
local color3=${colors[$((RANDOM % ${#colors[*]}))]}
while [[ $color1 == $color2 || $color1 == $color3 || $color2 == $color3 ]]
do
color2=${colors[$((RANDOM % ${#colors[*]}))]}
color3=${colors[$((RANDOM % ${#colors[*]}))]}
done
case $((RANDOM % 4)) in
0) slant=-2;;
1) slant=-1;;
2) slant=1;;
3) slant=2;;
esac
if [[ $height -gt 5 ]]; then
h=$height
while [[ $h -gt 0 ]]
do
colorstr $row $col $color1 '.'
let row--
if [[ $((col + slant)) -ge $((cols - 3)) || $((col + slant)) -le 2 ]]; then break; fi
let col+=slant
let h--
sleep 0.1
done
if [[ $((col + slant)) -lt $((cols - 3)) && $((col + slant)) -gt 2 ]]; then
h=$((height / 5))
while [[ $h -gt 0 ]]
do
colorstr $row $col $color2 '.'
let row++
if [[ $((col + slant)) -ge $((cols - 3)) || $((col + slant)) -le 2 ]]; then break; fi
let col+=slant
let h--
sleep 0.1
done
fi
colorstr $((row)) $((col - 1)) $color3 '***'
colorstr $((row - 1)) $((col)) $color3 '*'
colorstr $((row + 1)) $((col)) $color3 '*'
fi
}
for i in $(seq 1 $nsingle)
do
clear
fireworks
sleep 1
done
clear
pids=
for i in $(seq 1 $nmultiple)
do
let multiple++
lock_file=$lock_file_base.$i
fireworks &
pids="$pids $!"
done
trap "kill -9 $pids 2>/dev/null" EXIT
wait $pids
sleep 3
clear
center_colorstr $((rows / 2 - 1)) red "Hope you enjoyed the show!"
center_colorstr $((rows / 2 + 1)) red "Happy New year!! "
center_colorstr $((rows / 2 + 3)) red "Computothought"
echo
sleep 5
clear
# vim: tabstop=4: shiftwidth=4: noexpandtab:
# kate: tab-width 4; indent-width 4; replace-tabs false;
[/code]
Create shell batch file:
$ vim fireworks.sh
Make it executable:
$ chmod +x fireworks.sh
Run it:
$ ./fireworks.sh
Must be run on a linux box with figlet installed.
$ sudo apt-get update
$ sudo apt-get install figlet
Code:
$ while [[ $(date +%Y) -ne 2012 ]];do figlet $(($(date -d 2012-01-01 +%s)-$(date +%s)));sleep 1;clear;done;figlet 'Happy New Year!'
-----------------------------------------------------------------
Fireworks:
Fireworks.sh
[code]
#!/bin/bash
rows=$(tput lines)
cols=$(tput cols)
colors=(red green blue purple cyan yellow brown)
lock_file=
lock_file_base=/tmp/$(basename $0 .sh)
multiple=0
if [[ "$1" ]]; then
nsingle=$1
shift
else
nsingle=10
fi
if [[ "$1" ]]; then
nmultiple=$1
shift
if [[ $nmultiple -gt 8 ]]; then nmultiple=8; fi
else
nmultiple=6
fi
function colorstr()
{
local row=$1
local col=$2
local color=$3
local v
case "$color" in
red) v=31;;
green) v=34;;
blue) v=32;;
purple) v=35;;
cyan) v=36;;
yellow) v=33;;
brown) v=33;;
white) v=37;;
*) v=;;
esac
shift 3
if [[ $multiple -ne 0 ]]; then
touch $lock_file
while [[ $(ls $lock_file_base.* 2>/dev/null | head -n 1) != $lock_file ]]
do
sleep 0.05
done
fi
tput cup $row $col
echo -n -e "\e["$v"m"
set -f
echo -n $*
set +f
if [[ $multiple -ne 0 ]]; then
rm -f $lock_file
fi
}
function center_colorstr()
{
local row=$1
local color=$2
shift 2
local s="$*"
local slen=${#s}
colorstr $row $(((cols / 2) - (slen / 2))) $color "$s"
}
function fireworks()
{
local row=$((rows - 1))
local col=$(((RANDOM % (cols / 2)) + (cols / 4)))
local height=$((RANDOM % rows - 2))
local slant
local h
local color1=${colors[$((RANDOM % ${#colors[*]}))]}
local color2=${colors[$((RANDOM % ${#colors[*]}))]}
local color3=${colors[$((RANDOM % ${#colors[*]}))]}
while [[ $color1 == $color2 || $color1 == $color3 || $color2 == $color3 ]]
do
color2=${colors[$((RANDOM % ${#colors[*]}))]}
color3=${colors[$((RANDOM % ${#colors[*]}))]}
done
case $((RANDOM % 4)) in
0) slant=-2;;
1) slant=-1;;
2) slant=1;;
3) slant=2;;
esac
if [[ $height -gt 5 ]]; then
h=$height
while [[ $h -gt 0 ]]
do
colorstr $row $col $color1 '.'
let row--
if [[ $((col + slant)) -ge $((cols - 3)) || $((col + slant)) -le 2 ]]; then break; fi
let col+=slant
let h--
sleep 0.1
done
if [[ $((col + slant)) -lt $((cols - 3)) && $((col + slant)) -gt 2 ]]; then
h=$((height / 5))
while [[ $h -gt 0 ]]
do
colorstr $row $col $color2 '.'
let row++
if [[ $((col + slant)) -ge $((cols - 3)) || $((col + slant)) -le 2 ]]; then break; fi
let col+=slant
let h--
sleep 0.1
done
fi
colorstr $((row)) $((col - 1)) $color3 '***'
colorstr $((row - 1)) $((col)) $color3 '*'
colorstr $((row + 1)) $((col)) $color3 '*'
fi
}
for i in $(seq 1 $nsingle)
do
clear
fireworks
sleep 1
done
clear
pids=
for i in $(seq 1 $nmultiple)
do
let multiple++
lock_file=$lock_file_base.$i
fireworks &
pids="$pids $!"
done
trap "kill -9 $pids 2>/dev/null" EXIT
wait $pids
sleep 3
clear
center_colorstr $((rows / 2 - 1)) red "Hope you enjoyed the show!"
center_colorstr $((rows / 2 + 1)) red "Happy New year!! "
center_colorstr $((rows / 2 + 3)) red "Computothought"
echo
sleep 5
clear
# vim: tabstop=4: shiftwidth=4: noexpandtab:
# kate: tab-width 4; indent-width 4; replace-tabs false;
[/code]
Create shell batch file:
$ vim fireworks.sh
Make it executable:
$ chmod +x fireworks.sh
Run it:
$ ./fireworks.sh
Step 13: Ascii Art.
There is a lot of ascii art on the net but it is disappearing fast..
__ __ __ __ _ / //_/_ ______ ____ _ / / / /__ (_) / ,< / / / / __ \/ __ `/ / /_/ / _ \/ / / /| / /_/ / / / / /_/ / / __ / __/ / /_/ |_\__,_/_/ /_/\__, / /_/ /_/\___/_/ /____/ ______ __ ________ / ____/___ _/ /_ / ____/ /_ ____ __ __ / /_ / __ `/ __/ / / / __ \/ __ \/ / / / / __/ / /_/ / /_ / /___/ / / / /_/ / /_/ / /_/ \__,_/\__/ \____/_/ /_/\____/\__, / /____/ ___......----:'"":--....(\ .-':'"": : : : : : :.(1\.`-. .'`. `. : : : : : : : : : : .'; :-`. : . : : `. : : :. : :`.`. a; : ;-. `-.-._. : : : ::. .' `. `., = ; :-:.` .-. _-., : : : ::,.'.-' ;-. ,'''" .'.' ;`. .-' `-.: : : : :;.-'.-.' `-' :. .'.'.-' .'`-.' -._;..:---'''"~;._.-; :`--'.' : :' ;`-.; :.`.-'`. `'"` : : ;`.; :=; `.-'`. : '. : ; :-: `._-`. `'"' `. `. `--' `._; `'"' | _____ | _____ \ / /______ | | / /_ / | | ()____)+()____) ----- / | | -+-. /_.|_|/_. | | ()____)+()____) \ / /___ __|__ | | | | / | | / | | ()____)+()____) ----- | | | | |_| _|_|_ /_\`-'/_\ | | ()____)+()____) __|__ | | __|_|____ | | ___|___ | | ()____)+()____) /|\ | | | | / \ _/|\_ * * / | \ __ __ ____ __ __ __ _ \ \/ /__ ____ ______ ____ / __/ / /_/ /_ ___ / /_(_)___ ____ _____ \ / _ \/ __ `/ ___/ / __ \/ /_ / __/ __ \/ _ \ / __/ / __ `/ _ \/ ___/ / / __/ /_/ / / / /_/ / __/ / /_/ / / / __/ / /_/ / /_/ / __/ / /_/\___/\__,_/_/ \____/_/ \__/_/ /_/\___/ \__/_/\__, /\___/_/ /____/
Step 14: Starwars
You can also watch the Starwars video with a real telnet connection.
$ telnet towel.blinkenlights.nl
You can also save the telnet session with ttyrec (you may need to install ttyrec or compile from source at http://sourceforge.net/projects/ttyrec/ , if your distro does not have it included) for later playback.
$ ttyrec starwars
$ telnet towel.blinkenlights.nl
<control>d (control + d)
$ ttyplay starwars.
Step 15: Simple Metronome.
simple metronome program that works on ascii terminals. there is no sound just all visual. You can call the program with
$ ./metronome [speed]
Compile the code with:
$ gcc metronome.c -o metronome
Attachments
Step 16: Holiday Trees.
Step 17: Arduino Ascii Output.
The c compiler just loves the "\".






