Snowman screen saver with music (iPad/iPhone)

Post Reply
User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Snowman screen saver with music (iPad/iPhone)

Post by Dav »

I meant to post this before Christmas, but got behind. It's a snowman screen saver that shows a winter scene animation while playing various Christmas carols and songs. It should work on all devices.

On first run, the program will download the needed media files from off my website (I don't do Dropbox). It shouldn't take long at all. After that the screen saver will run.

While playing, touch the sides of the screen to cycle through the midi song files. Left side goes backwards, right side goes forward to next song. Touch any other area of screen exits the program.

All media files were found in public domain. Hope you enjoy this and have a (belated) Merry Christmas.

- Dav

Code: Select all

'snowman.txt v1.0
'A Snowman Screensaver (ipad/iphone)
'Coded by Dav DEC/2016 - for Christmas.
'Visit my site at: http://www.qbasicnews.com/dav

'Shows a winter scene animation while playing
'17 Christmas songs in the background. Something
'nice to look at & listen to on Christmas.
'Put on your table/desk to create holiday mood.

'ALL MEDIA FILES WERE FOUND IN PUBLIC DOMAIN.

'==============================================

'PLAYING CONTROLS...skipping songs...quitting

'Touch the left side of screen to go backward
'through the song list (play previous song).

'Touch right side of screen to move forward to
'the next song.

'Touch the middle of screen to end program.

'==============================================
'NOTE: ON FIRST RUN THIS PROGRAM WILL ATTEMPT
'TO DOWNLOAD NEEDED MEDIA FILES FROM MY WEBSITE.
'THIS WILL ONLY NEED TO BE DONE ONCE.
'==============================================

'flag to control background music. 1=on,0=off
music=1 'music will play during animation

option base 1
set toolbar off
set orientation left
get screen size sw,sh
option screenlock off

'make the list of 17 .mid files
songmax= 17
dim song$(songmax)
for t=1 to songmax
  a$=str$(t)!if len(a$)=1 then a$="0"&a$
  song$(t)=a$&".mid"
next t

'see if media files present first
gosub checkinstall

graphics
graphics clear 0,0,0

draw text " Loading..." at sw/2-75,sh/2

'load sprite animation
sprites delete
option sprite pos central
sprite "1" load "snowman-data/snowman.png",5,3
sprite "1" resize sw,sh
sprite "1" at sw/2,sh/2 scale 1
sprite "1" show
sprite "1" delay .12
sprite "1" loop

'start a song if music flag is on
if music=1 then
   song=rnd(songmax)+1 'choose a random song
   notes load "snowman-data/"&song$(song)
   notes play
end if

'================
'the main loop...
'================

do

   if music=1 then gosub checkmusic
   slowdown

   'get screen touch...
   if touch_x(0)<> -1 then
      x=touch_x(0) ! sx=sw/5

      'left side of screen touched...
      'go backwards in song list
      if x>1 and x<sx then
        notes stop
        song = song -1
        if song<1 then song = songmax
        notes load "snowman-data/"&song$(song)
        notes play
        'wait until finger up..
        do!until not touch_x(0)<> -1 
      end if

      'right side of screen touched...
      'go forward in song list
      if x>(sw-sx) and x<sw then
        notes stop
        song = song +1
        if song>17 then song = 1
        notes load "snowman-data/"&song$(song)
        notes play
        do!until not touch_x(0)<> -1
      end if

      'touch middle of screen quits...
      if x>sx and x<sw-sx then
        break
      end if

   end if
until forever

set toolbar on
sprite "1" delete
text
end



'=================================
' G O S U B S / F U N C T I O N S
'=================================


'=========
checkmusic:
'=========

'if song over, load the next one
if notes_time() => notes_length() then
   song=song+1 ! if song>songmax then song=1
   notes load "snowman-data/"&song$(song)
   notes play
end if

return


'===========
checkinstall:
'===========

i=0 ! i$="snowman-data/"
'check to see if data files exist first.
if not file_exists(i$) then i=1
if not file_exists(i$&"snowman.png") then i=1
for t=1 to songmax
  a$=str$(t)!if len(a$)=1 then a$="0"&a$
  a$=a$&".mid"!if not file_exists(i$&a$) then i=1
next t

if i= 1 then gosub install

return


'======
install:
'======

'set orientation top
url$="www.qbasicnews.com/dav/snowman-data/"
print
print
print
print "SNOWMAN SCREEN SAVER INSTALL v1.0"
print
print "Before using this screen saver you must ";
print "download the needed media files. A folder ";
print "will be created called 'snowman-data' and ";
print "will take under 1MB of space. ";
print "It will download from: http://"&url$
print
print "You will only have to do this download once ";
print "unless you delete the 'snowman-data' folder."
print
print "MAKE SURE TO STAY CONNECTED TO THE ";
print "INTERNET DURING THE ENTIRE PROCESS."
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

text clear

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 "Creating 'snowman-data' folder...";
dir "snowman-data/" create
print "OK!"

redownload:
print "Downloading snowman.gif (565983 bytes)"
print "This may take a minute ..."
http url$&"snowman.gif" getdim m
file "snowman.gif" writedim m
if file_size("snowman.gif") <> 565983 then
   print "File not properly downloaded, retrying..."
   file "snowman.gif" delete
   goto redownload
end if

print "Generating snowman animation..."
sprites delete
sprite 1 load "snowman.gif"
sprite 1 save "snowman-data/snowman.png"
file "snowman.gif" delete

'download midi files...
for t=1 to songmax
  a$=str$(t)!if len(a$)=1 then a$="0"&a$
  a$=a$&".mid" ! f$="snowman-data/"&a$
  print "Downloading "; 
  print url$;
  print a$;
  print "...";
  http url$&a$ getdim m
  file "snowman-data/"&a$ writedim m
next t

text clear

return
Last edited by Dav on Wed Dec 28, 2016 12:14 am, edited 1 time in total.

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Snowman screen saver with music (iPad/iPhone)

Post by sarossell »

Dude! That is slick. But if that's what snow looks like in the Carolinas, I'm thrilled I live in sunny San Diego.

I had no idea loading files from the Internet was so easy. Just two lines of code! That's insane. Can you imagine what it must be like in other languages?

Thanks for the Christmas greeting. I don't celebrate Christmas myself, but ironically, the two (and only) Christmas greetings I got this year were on this forum. Nice.
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Snowman screen saver with music (iPad/iPhone)

Post by Dav »

Thanks, sarossell. Yes, downloading is a breeze in smart Basic!

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Snowman screen saver with music (iPad/iPhone)

Post by rbytes »

Never too late to enjoy Christmas songs! Thanks, Dav.
The only thing that gets me down is gravity...

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Snowman screen saver with music (iPad/iPhone)

Post by Dav »

Thanks rbytes. Glad you like it. I Usually don't get tired of Christmas music either, but after so many Christmas gigs this month, I'm kind of looking for a little rest from them, lol.

- Dav

Post Reply