View Single Post
Old 03-09-2012, 10:46 AM   #11
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3


ddplot

UPDATE: Changed "virtual_xres" to "line_length" to for Kindle 3 compatibility.

Now that this thread has devolved into a discussion on the dd command, we might say that the "great and powerful" dd can also be used for "unusual" things like this (try it on a k4 or touch):

ddplot script code:
PHP Code:
#/bin/sh

set $(eips -i|grep line_length)
VX=$# fb0:line_length

n=0
while [[ $n -lt 600 ]]; do
  
n=$((n+1))
  
C0="$C0$(echo -ne '\xff')" # white
  
C1="$C1$(echo -ne '\x01')" # black (no '\x00' in string)
done

plot
() {
  
local X=$1local Y=$2local C=$3
  
echo $C|dd of=/dev/fb0 bs=1 count=1 seek=$((Y*VX+X)) 2>/dev/null
}  

hline() {
  
local X=$1local Y=$2local L=$3local C=$4
  
echo $C|dd of=/dev/fb0 bs=1 count=$L seek=$((Y*VX+X)) 2>/dev/null
}

vline() {
  
local X=$1local Y=$2local L=$3local C=$4
  
while [[ $L -gt 0 ]]; do
    
L=$((L-1))
    
plot $X $Y $C
    Y
=$((Y+1))
  
done 
}

fline() { # forward-slash
  
local X=$1local Y=$2local L=$3local C=$
  
while [[ $L -gt 0 ]]; do
    
L=$((L-1))
    
plot $((X+L)) $Y $C
    Y
=$((Y+1))
  
done
}

bline() { # back-slash
  
local X=$1local Y=$2local L=$3local C=$4
  
while [[ $L -gt 0 ]]; do
    
L=$((L-1))
    
plot $((X+L)) $((Y+L)) $C
  done
}

eips --# flash clear

vline 233 100 400 $C1
hline 100 233 400 $C1
eips ''
vline 367 100 400 $C1
hline 100 367 400 $C1
eips ''
n=3
while [[ $n -gt 0 ]]; do
  
n=$((n-1))
  
bline 160 160 280 $C1eips ''
  
fline 160 160 280 $C1eips ''
  
bline 160 160 280 $C0eips ''
  
fline 160 160 280 $C0eips ''
done
bline 160 160 280 $C1
eips ''
fline 160 160 280 $C1eips ''

vline 300 100 400 $C1
hline 100 300 400 $C1
eips ''

vline 233 100 400 $C0
hline 100 233 400 $C0
eips ''                  
vline 367 100 400 $C0                           
hline 100 367 400 $C0
eips '' 
I have also implemented Bresenham's line and circle algorithms (for round-cornered vector buttons) and the Hershey vector fonts and a bitmap blitter for raster fonts, all using dd in an sh shell. Binary data processing in a shell script is said to be "impossible" if you trust what Google finds on this subject. For me, "impossible" is just another challenge.

And as you may have already seen in the "touchscreen ascii fingerpaint" thread, the hexdump command can similarly be "abused" to read binary touchscreen event device data. But hexdump also supports offsets like dd, so it can read raw binary pixel data, to complement writing pixels with dd above. Who would have thought you could implement GetPixel() and SetPixel() functions in a shell script using only hexdump and dd to process individual bytes of binary data? And yet, it is MUCH faster than plotting graphics with BASIC in the "olden days".

Sadistic hobby, eh?

UPDATE: This script calls eips to refresh the eInk display, and dd to write binary pixel data to the framebuffer, and it would need a third external program hexdump to read binary framebuffer pixels and binary touchscreen event data and/or keypress events, if you wish to add such features. See my touchpaint script for an example.

CHALLENGE: Who will be the first to implement a C compiler using only sh built-in shell features and the dd external program to output the binary compiled executable program?

UPDATE: This post spawned a separate "eink algorithmic art shell scripting" thread here:


Last edited by geekmaster; 10-31-2012 at 02:41 PM.
geekmaster is offline   Reply With Quote