Page 1 of 1

Card trick

Posted: Sun Feb 13, 2022 3:27 pm
by Henko
Hi,
2 programs. One to load and save a set of playing cards from internet (program and cards-file from Dave), and one program which uses the cards file for a trick.
4CBD85F1-A198-4044-96FA-165F0C164914.png
4CBD85F1-A198-4044-96FA-165F0C164914.png (2.37 MiB) Viewed 7407 times

First program:

Code: Select all

'cards.txt v1.0 (iphone/ipad)
'Demos a nice deck of cards using a sprite sheet.
'Downloads 'cards.png' sprite sheet from internet.
'You can use this sprite sheet to make card games.
'The sprite sheet is small, only 40k in size.
'Coded by Dav, OCT/2017

'NOTE: This programs saves 'cards.png' in current dir.
'      On first run it will download it off internet.

option base 1

if not file_exists("cards.png") then
   gosub download
end if

graphics
graphics clear 0,.5,.2
get screen size sw,sh

sprite "cards" load "cards.png", 14,4
sprite "cards" show

'Now show all frames of sprite...
'(52 number cards, 2 backs, 2 jokers)

' do
  for f =1 to 56
    refresh off
    sprite "cards" frame  int(rnd(55))+1' 39+14*rnd(2)+rnd(3)
' int(rnd(55))+1
    sprite "cards" at rnd(sw),rnd(sh) scale .9 angle rnd(255)/255
    sprite "cards" stamp
    refresh on
    ' pause .5
  next f
' until forever

end


'=======
download:
'=======

url$="www.qbasicnews.com/dav/files/cards.png"
print
print
print
print "DOWNLOAD CARDS.PNG SPRITE SHEET?"
print
print "This program requires the file cards.png.";
print "It is only about 40k in file size and will ";
print "download from: http://"&url$
print
print "It will be saved in the current folder. ";
print "You will only have to download it once ";
print "unless you delete the cards.png file."
print

button "download" text "Proceed" at 25,10
button "no" text "Not now, maybe later" at 150,10

do 
  if button_pressed("no") then end
until button_pressed("download")

button "download" delete
button "no" delete

if system_ext_ip$() ="" then
   print "Error!"
   print
   print "You do not appear to be online. ";
   print "Please connect to the internet first and ";
   print "try running program again."
   print
   print "STOPPED..."
   end
end if

print "Downloading..."

http url$ getdim m
file "cards.png" writedim m
return
Second program:

Code: Select all

graphics ! graphics clear ! draw color 0,0,1
option base 1 ! option angle degrees
get screen size sw,sh ! cx=sw/2 ! cy=sh/2+130
field "p" text " touch" at cx-70,552 size 140,140 RO
field "p" back color 0,1,0
field "p" font size 42
field "p" hide
n=6 ! dtet=360/n ! R=240 ! ns=1 ! ft$="Courier-BoldOblique"
dim zw(n),rd(n),sel(n)
draw_banner("Hi there !",20,10,ft$,40,.1)
draw_banner("I can read your mind.",20,40,ft$,40,.1)
draw_banner("Pick a card in your mind,",20,70,ft$,40,.1)
draw_banner("I will shuffle the cards,",20,100,ft$,40,.1)
draw_banner("and remove the card you chose.",20,130,ft$,40,.1)
draw_banner("Scary !!",20,160,ft$,40,.1) ! pause .5
draw_banner("Here are the cards:",20,190,ft$,40,.1)
draw_banner("you have 3 seconds.",20,220,ft$,40,.1)

f$="cards" ! option sprite pos central
sprite "cards" load "cards.png", 14,4

for i=0 to 2
  zw(i+1)=11+i ! zw(i+4)=25+i ! rd(i+1)=39+i ! rd(i+4)=53+i
  next i
for i=0 to 2
  do ! k=1+rnd(6) ! until zw(k)>0
  sel(2*ns)=zw(k) ! zw(k)=0
  do ! k=1+rnd(6) ! until rd(k)>0
  sel(2*ns-1)=rd(k) ! rd(k)=0 ! ns+=1
  next i
for i=1 to n ! sprite f$ copy f$&i ! next i
for i=1 to 6
  tet=i*dtet ! x=cx+R*cos(tet) ! y=cy+R*sin(tet)
  sprite "cards" frame sel(i)
  sprite "cards" at x,y scale 2 angle tet+90
  sprite "cards" stamp
  pause .1
  next i

pause 3
graphics clear
draw_banner("Shuffling....",20,160,ft$,40,.1)
pause 2

ns=1
for i=1 to 6
  if zw(i) then ! sel(ns)=zw(i) ! ns+=1 ! end if
  if rd(i) then ! sel(ns)=rd(i) ! ns+=1 ! end if
  next i
weg=1+rnd(6)
for i=1 to 6
  if i=weg then continue
  tet=i*dtet ! x=cx+R*cos(tet) ! y=cy+R*sin(tet)
  sprite "cards" frame sel(i)
  sprite "cards" at x,y scale 2 angle tet+90
  sprite "cards" stamp
  pause .5
  next i
draw_banner("Scary, huh ?",20,210,ft$,60,.1)
pause 2 ! graphics clear
end

' draw a text token after token
' t$ is the textstring
' x,y is starting position
' fn$ is the name of the font to be used
' fs is the font size
' paus is the pause after each token
'
def draw_banner(t$,x,y,fn$,fs,paus)
fsiz=font_size() ! ob=option_base()
draw font name fn$ ! draw font size fs
dx=.6*fs ! lt=len(t$)+ob-1
for i=ob to lt
  a$=mid$(t$,i,1) ! draw text a$ at x,y ! x+=dx
  pause paus
  next i
draw font size fsiz
end def