Post by tsh73 on Aug 9, 2023 16:06:21 GMT -5
follow-up to this thread
libertybasiccom.proboards.com/thread/2321/liberty-basic-active?page=2
So there is a single picture with cards
iitutor.com/wp-content/uploads/h5p/content/2557/images/file-60924ed47fc9b.png
(actually I added it as attachment below, it's only 36k)
Create a folder
Save it there as a cards.bmp
(or save as your browser allows you, then resave it as BMP with Paint)
Run this program, it will save single cards as 2C.bmp...TS.bmp (52 bitmaps)
Now here's modified RB program that will work in LB - read these cards and draw it in graphic window.
libertybasiccom.proboards.com/thread/2321/liberty-basic-active?page=2
So there is a single picture with cards
iitutor.com/wp-content/uploads/h5p/content/2557/images/file-60924ed47fc9b.png
(actually I added it as attachment below, it's only 36k)
Create a folder
Save it there as a cards.bmp
(or save as your browser allows you, then resave it as BMP with Paint)
Run this program, it will save single cards as 2C.bmp...TS.bmp (52 bitmaps)
'read in cards images
'https://iitutor.com/wp-content/uploads/h5p/content/2557/images/file-60924ed47fc9b.png
' save it as "cards.bmp"
nomainwin
path$=DefaultDir$+"\cards.bmp"
'950x392
'73x98
w1=73:h1=98
w=72:h=96 'some trial and error needed to ge exact card size
suite$ = "C,D,H,S" ' Club,Diamond,Heart,Spades
card$ = "A,2,3,4,5,6,7,8,9,T,J,Q,K" ' Cards Ace to King
suite$ = "C,S,H,D" 'change to match to actual picture
WindowWidth=1000
WindowHeight=500
open "cards" for graphics_nsb_nf as #gr
#gr "trapclose [quit]"
#gr "down"
loadbmp "cards", path$ 'read all sheet
#gr "drawbmp cards 1 1" 'draw all sheet
'we need it all because way to load part of bitmap is to grab it back off screen
for r = 1 to 4 'rows
for c= 1 to 13 'cols
x=(c-1)*w1+2
y=(r-1)*h1+2
bmpName$="b";r;c 'like, 12 or 310 or 413
#gr "getbmp ";bmpName$;" ";x;" ";y;" ";w;" ";h
'print r,c,"getbmp ";bmpName$;" ";x;" ";y;" ";w;" ";h
next
next
'now draw what we got
#gr "cls"
#gr "fill cyan"
for r = 1 to 4 'rows
for c= 1 to 13 'cols
x=(c-1)*w1+2
y=(r-1)*h1+2
bmpName$="b";r;c 'like, 12 or 310 or 413
'print r,c,"drawbmp ";bmpName$;" ";x;" ";y
'if rnd(0)<0.2 then
#gr "drawbmp ";bmpName$;" ";x;" ";y
'end if
'now save them under names RB program expects them
s = r ' determine suite 'suite = row
c = c ' determine card 'happened to be card = column
cardId$ = word$(card$,c,",");word$(suite$,s,",");".bmp" 'because native format for LB is BMP
bmpsave bmpName$, cardId$
next
next
#gr "flush"
wait
[quit]
close #gr
end
Now here's modified RB program that will work in LB - read these cards and draw it in graphic window.
projectDir$ = "a_project" ' project directory
imageDir$ = DefaultDir$ + "\projects\" + projectDir$ + "\image\" ' directory of deck images
imagePath$ = "../";projectDir$;"/image/" ' path of deck images
suite$ = "C,D,H,S" ' Club,Diamond,Heart,Spades
card$ = "A,2,3,4,5,6,7,8,9,T,J,Q,K" ' Cards Ace to King
dim n(55) ' make ordered deck
for i = 1 to 52 ' of 52 cards
n(i) = i
next i
for i = 1 to 52 * 3 ' shuffle deck 3 times
i1 = int(rnd(1)*52) + 1
i2 = int(rnd(1)*52) + 1
h2 = n(i1)
n(i1) = n(i2)
n(i2) = h2
next i
nomainwin 'set console window off
'open window to draw upon
WindowWidth=600
WindowHeight=300
open "cards" for graphics_nsb_nf as #gr
#gr "trapclose [quit]" 'set "close" handler
#gr "down" 'put pen down so we can draw
for yy = 1 to 8 ' display 7 across and 8 down
for xx = 1 to 7
card = card + 1
s = (n(card) mod 4) + 1 ' determine suite
c = (n(card) mod 13) + 1 ' determine card
'cardId$ = word$(card$,c,",");word$(suite$,s,",");".gif"
'native LB format is BMP
cardId$ = word$(card$,c,",");word$(suite$,s,",");".bmp"
'html "<div style='position: relative; left:";(xx -1) * 80;"px; top:";(yy -1) * 20;"px; height:0px; width:0px;>"
'html "<div style='width:100px; height:100px; border:solid 0px #000;'>"
'html "<img src=";imagePath$;cardId$;" width=70px >"
'html "</div></div>"
'get that position
left=(xx -1) * 80
top=(yy -1) * 20
'load bitmap by name (here we laad all cards to single "card" name, overriding them.
'Could as well use different names to draw it without loading again)
loadbmp "card", cardId$
'loadbmp cardId$, cardId$ 'different names
'put it to desired place
#gr "drawbmp card ";left;" ";top
'#gr "drawbmp "; cardId$;" ";left;" ";top 'different names
'if card = 52 then end ' out of cards
if card = 52 then #gr, "flush":wait 'wait for close event (allow to see what we draw)
next xx
next yy
[quit] 'close window then "X" clicked
close #gr
end