Plan 9 from Bell Labs’s /usr/web/sources/contrib/rog/sh-examples/draw/mkcards.sh

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/dis/sh
load expr

bind -a . /dis
or {cd cards} {raise 'can''t cd'}
suits:=suit^(0 1 2 3)^.bit
nums:=num^${expr 0 12 seq}^.bit

fn isred {
	~ $1 suit1.bit suit2.bit
}

subfn inset {
	(inset minx miny maxx maxy) = $*
	result=${expr $minx $inset + $miny $inset + $maxx $inset - $maxy $inset -}
}

r:=0 0 24 32
bg:=white
border:='#aaaaaa'

pos0:=2 2
pos1:=15 2
pos2:=2 23
pos3:=15 23

# fake bitmaps
{} {
	mkimage black 7 7 > suit0.bit
	mkimage red 7 7 > suit1.bit
	mkimage red 7 7 > suit2.bit
	mkimage black 7 7 > suit3.bit
	for i in $nums {
		mkimage red 6 8 > red^$i
	}
	for i in $nums {
		mkimage black 6 8 > black^$i
	}
	mkimage $border $r | draw 1 1 ${pipe from {mkimage $bg ${inset 1 $r}}} > base.bit
}

cardnum:=0
for num in $nums {
	for suit in $suits {
		n := black^$num
		if {isred $suit} {
			n = red^$num
		}
		< base.bit draw $pos0 $n $pos1 $suit $pos2 $suit $pos3 $n > $cardnum.bit
		cardnum=${expr $cardnum 1 +}
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.