fi.sh - a Boids clone in Bash
posted 2010-02-22 19:29:02,
link to this article
Read full article
After squa.sh,
I thought it was time for another abuse of the Bash shell.
A few weeks ago I wrote fi.sh, a simulation of flocking behaviour, like migrating birds or
a school of fish, written in pure Bash and with ascii-art graphics, of course.
Fi.sh is inspired by the classic Boids algorithm by Craig Reynolds. But since I wrote this in a week when I was in the middle of nowhere in Andalucia, without any means of connecting to the Internet it only uses two behaviours, instead of Reynolds’ three, still the results look pretty convincing.
Craig Reynolds original Boids
Progress bars in Bash
posted 2009-08-10 07:20:31, link to this article
Today a colleague reminded me to dig up a script that I wrote some years ago to generate progress bars (or actually generic horizontal bar graphs) in Bash.
The script is, in this state, more like a proof of concept. It displays an bar that increments until full and then decrements again, this cycle is repeated forever. It should not be too hard to rewrite it to be used in something more useful.
I think it's also trivial to rewrite this to display vertical bar graphs as well. I might write a small Bash library to include in other scripts later, if and when I feel the need to. ;-)
The code of the script follows below, enjoy...
#!/bin/bash
# progress bar
# Hessel Schut, VPRO Automatisering, 2004-04-02
cols=$(tput cols)
bold=$(tput smso)
norm=$(tput rmso)
trap cleanup EXIT TERM INT
cleanup() {
norm
tput clear
tput cnorm
exit
}
hor_line() {
for ((i=1; i < cols - 2; i++)); do
echo -n '-'
done
}
draw_frame() {
tput cup 2 2; hor_line
tput cup 3 1; echo -n '|'
tput cup 3 ${cols}; echo -n '|'
tput cup 4 2; hor_line
}
tput clear
tput civis
draw_frame
d=1; pos=2; plen=0
while [ == ]; do
[ $d -eq 1 ] && face=${bold}
tput cup 3 $pos
echo -n ${face}' '
face=${norm}
sts='pos: '${pos}' dir: '${d}
tput cup 1 1; echo -n ${norm}${sts}
[ ${plen} -gt ${#sts} ] && for ((i=0; i < plen - ${#sts}; i++)); do
echo -n ' '
done
plen=${#sts}
((pos += d))
[ $pos -gt 2 ] && [ $pos -lt $((cols - 2 )) ] || ((d=-d))
done
UDGBUF: a poor man's framebuffer on Psion Organiser II, Part 1
posted 2009-06-13 21:57:15, link to this article
Today I had some more fun with my rediscovered Psion Organiser II. It's about time to get my hands on a model LZ or LZ64 to enjoy twice the amount of screen real estate. ;)
This time I toyed with UDG (user defined characters) again. As the Psion reference manual states you can use these to make small animations as updating these changes them on screen immediately. That gave me the idea to implement some minimalistic framebuffer using all eight UDGs. I print four static UDGs in screen row 1, the other four in screen row 2, this way you get a whopping 40x16 pixel space for graphics!
It would be nice to read/write to the display controller directly and provide some convenience functions to do basic drawing, but I don't feel like learning to write HD6303 machine code just yet, so for now I plan to pass a pointer to some shadow memory (which I plan to allocate by creating a large global array or string) around where you do your graphics stuff, this will be then copied to the UDGs.
As a first test, I wrote a small program that walks through the memory of the Psion and displays it in the UDGs, with this result:
Tomorrow, I'll try to write some functions to provide a few basic graphics operations to set and get a pixel value. And maybe even some Bressenham line/circle drawing after that.
Psion Organiser II bargraphs
posted 2009-06-07 16:48:12, link to this article
Today, when searching for some other stuff, I came across some OPL (Organiser Programming Language, some sort of Pascal-ish bastard child of BASIC) code that I must have written around 2000, or so.
One of the programs was a set of functions to display bargraphs using user-defined characters on the two line text LCD of the Psion Organiser II. So I dug out my trusty old Psion Organiser II XP and cleaned up the code a bit.

This might be of use to someone, therefore I publish it here.
udg:(x%, b0%, b1%, b2%, b3%, b4%, b5%, b6%, b7%) pokeb $180, 64 + x%*8 pokeb $181, b0%; pokeb $181, b1% pokeb $181, b2%; pokeb $181, b3% pokeb $181, b4%; pokeb $181, b5% pokeb $181, b6%; pokeb $181, b7% bargudg: udg:(0, 0, 0, 0, 0, 0, 0, 0,31) udg:(1, 0, 0, 0, 0, 0, 0,31,31) udg:(2, 0, 0, 0, 0, 0,31,31,31) udg:(3, 0, 0, 0, 0,31,31,31,31) udg:(4, 0, 0, 0,31,31,31,31,31) udg:(5, 0, 0,31,31,31,31,31,31) udg:(6, 0,31,31,31,31,31,31,31) udg:(7,31,31,31,31,31,31,31,31) barchr$:(n%) if n% > 8 n% = 8 endif if n% = 0 return " " endif return chr$(n% - 1)
When you add these functions to your Organiser, after calling bargudg: you can call barchr$:() just like chr$() to print bargraph characters to the screen or to concatenate them to a string. barchr$:() accepts integers in the range 0..8, 0 being actually a space, not an UDG.
JavaScript Cellular Automata Simulation of Fluid-flow
posted 2009-05-23 11:13:28,
link to this article
Read full article
Yesterday, I tried to make a simple Cellular Automaton-like discrete simulation of fluid-flow. Or I am not even sure flow is the right word, it simulates waves coming from the left, with an adjustable frequency, hitting obstacles in their path.
My simulation is by no means attempting to be correct in any way but it is nice to play with and I even spotted something resembling the canceling of waves when passing to a double slit.
Most of the work went into convincing JavaScript to do what I wanted, without being able to use Firebug due to some obscure bug. Maybe I'll write some more about the code behind this in a later article.
I also plan to make it possible to save the configuration of the obstacles in a later version.
Follow the read link to give it a try.
TagPop: the making of
posted 2009-05-19 12:28:36,
link to this article
Read full article
As promised before, here is a description of the inner workings of TagPop.
TagPop is a tag cloud of all tags used on this website, in which the size of each tag represent its popularity among the visitors of this site. The popularity is measured based on pageviews of individual articles.
TagPop Visualizes tags by popularity
posted 2009-04-22 17:59:45,
link to this article
Read full article
The tag cloud on the left side of this page displays tags assigned to articles. The size of each tag is determined on the number of articles to which this tag is assigned.
I was interested how this tag cloud looks like when the size is determined by the popularity of articles tagged with a certain tag among readers of isquared.nl.
To visualize this I have hacked together a quick application, called TagPop, to display the tags based on popularity, this is available here.
In a later post I will write more about the inner workings of TagPop.
isquared.nl rss (atom)