Author Topic: 'Tis the season, AGAIN! - Xmas contest  (Read 18354 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 'Tis the season, AGAIN! - Xmas contest
« Reply #45 on: December 24, 2018, 07:48:59 pm »
  • Best Answer
  • My attempt for this is a redoing of the old SDL christmas program I created a long time ago.  In the spirit of the rules, here's the whole program compiled up into a single stand-alone Windows EXE:  https://www.dropbox.com/s/wn7otd3hnjdt0tm/Merry%20Christmas.exe?dl=1



    To create this EXE takes several steps though:

    STEP 1 --  COPY THE FOLLOWING AND PASTE IT IN QB64.  SAVE AS "Merry Christmas.bas"  THEN JUST MAKE AN EXE OF THE CODE.  (DO NOT EXECUTE IT!!)

    Code: QB64: [Select]
    1.     x AS INTEGER
    2.     y AS INTEGER
    3.  
    4.  
    5. SCREEN _NEWIMAGE(620, 480, 256)
    6. DIM SHARED Lights(112) AS Point
    7. f& = _LOADFONT("OLDENGL.ttf", 72)
    8. MakeMusic
    9.     _LIMIT 3
    10.     CLS
    11.     DrawTree
    12.     InitializeLights
    13.     DrawLights
    14.     PrintGreetings
    15.     _DISPLAY
    16. EndMusic
    17.  
    18. SUB EndMusic
    19.     KILL "Frank Sinatra - Have Yourself A Merry Little Christmas.mp3"
    20.  
    21. SUB MakeMusic
    22.     OPEN "Merry Christmas.exe" FOR BINARY AS #1
    23.     OPEN "Frank Sinatra - Have Yourself A Merry Little Christmas.mp3" FOR BINARY AS #2
    24.     SEEK 1, LOF(1) - 6599478
    25.     DIM temp AS STRING * 6599478
    26.     'FOR i = 1 TO 6599478
    27.     GET #1, , temp
    28.     PUT #2, , temp
    29.     'NEXT
    30.  
    31.  
    32.     CLOSE
    33.     s& = _SNDOPEN("Frank Sinatra - Have Yourself A Merry Little Christmas.mp3")
    34.     _SNDLOOP s&
    35.  
    36. SUB PrintGreetings
    37.     _PRINTSTRING ((620 - _PRINTWIDTH("Merry Christmas")) / 2, 350), "Merry Christmas"
    38.  
    39.  
    40. SUB DrawLights
    41.     STATIC x
    42.     FOR i = 0 TO 112
    43.         clr = INT(RND(1) * 15 + 1)
    44.         CIRCLE (Lights(i).x, Lights(i).y), 2, clr
    45.         PAINT (Lights(i).x, Lights(i).y), clr
    46.     NEXT
    47.     x = x + 1
    48.     SELECT CASE x
    49.         CASE 1: COLOR 9
    50.         CASE 2: COLOR 10
    51.         CASE 3: COLOR 11
    52.         CASE 4: COLOR 12
    53.         CASE 5: COLOR 13
    54.         CASE 6: COLOR 14
    55.         CASE 7: COLOR 15
    56.         CASE ELSE: x = 0
    57.     END SELECT
    58.  
    59.  
    60.  
    61. SUB InitializeLights
    62.     FOR i = 0 TO 13
    63.         IF i MOD 2 = 0 THEN
    64.             FOR j = 0 TO i STEP 2
    65.                 z = z + 1
    66.                 'CIRCLE (310 - 7 * j, 30 + 20 * i), 2, 15
    67.                 Lights(z).x = 310 - 7 * j: Lights(z).y = 30 + 20 * i
    68.                 z = z + 1
    69.                 'CIRCLE (310 + 7 * j, 30 + 20 * i), 2, 15
    70.                 Lights(z).x = 310 + 7 * j: Lights(z).y = 30 + 20 * i
    71.             NEXT
    72.         ELSE
    73.             FOR j = 1 TO i STEP 2
    74.                 z = z + 1
    75.                 Lights(z).x = 310 - 7 * j: Lights(z).y = 30 + 20 * i
    76.                 'CIRCLE (310 - 7 * j, 30 + 20 * i), 2, 15
    77.                 z = z + 1
    78.                 Lights(z).x = 310 + 7 * j: Lights(z).y = 30 + 20 * i
    79.                 'CIRCLE (310 + 7 * j, 30 + 20 * i), 2, 15
    80.             NEXT
    81.         END IF
    82.     NEXT
    83.  
    84. SUB DrawTree
    85.     LINE (310, 10)-(200, 300), _RGB(34, 139, 34)
    86.     LINE (310, 10)-(420, 300), _RGB(34, 139, 34)
    87.     LINE (200, 300)-(420, 300), _RGB(34, 139, 34)
    88.     PAINT (310, 50), _RGB(34, 139, 34)
    89.     LINE (290, 301)-(330, 360), _RGB(165, 42, 42), BF


    STEP 2: Download the music file for this program from here: https://www.dropbox.com/s/9d1pqtqogrev2b9/Frank%20Sinatra%20-%20Have%20Yourself%20A%20Merry%20Little%20Christmas.mp3?dl=1


    STEP 3: RUN THE FOLLOWING CODE
    Code: QB64: [Select]
    1. OPEN "Merry Christmas.exe" FOR BINARY AS #1
    2. OPEN "Frank Sinatra - Have Yourself A Merry Little Christmas.mp3" FOR BINARY AS #2
    3. a$ = SPACE$(LOF(1))
    4. b$ = SPACE$(LOF(2))
    5. GET #1, , a$
    6. GET #2, , b$
    7. OPEN "MC.exe" FOR BINARY AS #3
    8. PUT #3, , a$
    9. PUT #3, , b$
    10. KILL "Merry Christmas.exe"
    11. NAME "MC.exe" AS "Merry Christmas.exe"
    12.  


    STEP 4: You now have a fully self contained EXE file called "Merry Christmas.exe".  Feel free to run it and look at my cheesy little tree, and listen to one of the great Christmas singers of old...


    It's a multi-step solution, but it 100% creates a completely self-contained file for us, in the end.  ;D











    https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

    Offline Pete

    • Forum Resident
    • Posts: 2361
    • Cuz I sez so, varmint!
      • View Profile
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #46 on: December 24, 2018, 10:34:23 pm »
  • Best Answer
  • Hi Guys
    just on timelimit... my little Christmas Card

    Happy Christmas to  everybody following his/her wishes!!!

    Buon Natale per chi crede e per chi non crede

    PS I have had so many confused ideas... so this is my little Christmas Card

    Let me guess. If you open it up it says...

    Money's short
    Times are hard
    Here's your QB
    Christmas card!

    Pete :D

    Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #47 on: December 24, 2018, 10:50:59 pm »
  • Best Answer
  • Hi Steve,

    I am getting an error on Line 33: (in main module), Bad record number, so no Frank...

    When I continue, it draws tree and lights OK. (Using your latest X 64).


    Offline SMcNeill

    • QB64 Developer
    • Forum Resident
    • Posts: 3972
      • View Profile
      • Steve’s QB64 Archive Forum
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #48 on: December 25, 2018, 12:23:43 am »
  • Best Answer
  • Hi Steve,

    I am getting an error on Line 33: (in main module), Bad record number, so no Frank...

    When I continue, it draws tree and lights OK. (Using your latest X 64).

    Is anti-virus or windows permissions at work?  Whitelist the file and “run as admin” and tell me if it still acts up.  Some windows security settings don’t like for a file to self-extract; thinking it’s a virus duplicating itself.
    https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

    Offline bplus

    • Global Moderator
    • Forum Resident
    • Posts: 8053
    • b = b + ...
      • View Profile
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #49 on: December 25, 2018, 09:53:20 am »
  • Best Answer
  • Hi Steve,

    OK I got it now, the trick was to save the setup bas file in the same folder as all the other files so it does it's work there instead of the main QB64 folder. I also deleted the Frank mp3 file to be sure to see a new one got created (while playing).
    (I also changed the default player to Windows Media from Groove because it was not playing correctly with Groove, doubt that made a difference.)

    This is neat way to add music to file. I imagine we could pile all kinds of files under the exe and just segment them off in giant sections to find them easily.
    « Last Edit: December 25, 2018, 10:12:01 am by bplus »

    Offline SMcNeill

    • QB64 Developer
    • Forum Resident
    • Posts: 3972
      • View Profile
      • Steve’s QB64 Archive Forum
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #50 on: December 25, 2018, 01:09:23 pm »
  • Best Answer
  • Hi Steve,

    OK I got it now, the trick was to save the setup bas file in the same folder as all the other files so it does it's work there instead of the main QB64 folder. I also deleted the Frank mp3 file to be sure to see a new one got created (while playing).
    (I also changed the default player to Windows Media from Groove because it was not playing correctly with Groove, doubt that made a difference.)

    This is neat way to add music to file. I imagine we could pile all kinds of files under the exe and just segment them off in giant sections to find them easily.

    You can.  It won’t compress them, so it ends up createing a huge singular exe for us, whose only purpose is ease of file distributation.  Still, that alone can be useful sometimes.  ;)
    https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

    Offline Petr

    • Forum Resident
    • Posts: 1720
    • The best code is the DNA of the hops.
      • View Profile
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #51 on: December 25, 2018, 04:03:36 pm »
  • Best Answer
  • Thank you Bplus and Steve for idea, here is it. Add more than 1 file to EXE and extract it from EXE.

    Zip contains one old exe program (from time developing ANI reader), original exe and new exe contains 5 added files. Source U1.BAS add files to EXE, and as output create TXT file which contains two DATA blocks. Copy this blocks to begin program U2.BAS and extract correctly from A.EXE this files. :-D  Add files are 4x BMP and 1x MP3.
    * multifile_adding_to_exe.zip (Filesize: 6.68 MB, Downloads: 323)

    Offline SMcNeill

    • QB64 Developer
    • Forum Resident
    • Posts: 3972
      • View Profile
      • Steve’s QB64 Archive Forum
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #52 on: December 25, 2018, 04:31:42 pm »
  • Best Answer
  • Thank you Bplus and Steve for idea, here is it. Add more than 1 file to EXE and extract it from EXE.

    Sounds like you need a copy of SAC — Steve’s Anorexic Code.  It’s a stand-alone program I wrote a few years back which does just that. 

    Use it from the command line by: 

    SAC -feed output.exe Afile.txt
    SAC -feed output.exe Anotherfile.mp3
    SAC -feed output.exe Whatever.png
    SAC -make output.exe

    With the above, it adds Afile.txt to output.exe, then Anotherfile.mp3 to output.exe...
    The make switch finalizes the EXE so it can self-extract with:

    output — by itself, it extracts everything into the folder where it’s at (creating file structure if needed for subdirectories)

    OR....

    output -pukeup Whatever.png — using the pukeup switch, you can extract individual file as needed.



    SAC used to be available at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there], and somebody around here might still have a copy of it floating around somewhere.  Heck, I probably have a copy of it archived somewhere in a backup folder,  if I can find it and dig it back out.  From past experience, it’s often just easier for me to rewrite the code than it is for me to find something once it’s been “put up for safe keeping”.  LOL!
    https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

    Offline Petr

    • Forum Resident
    • Posts: 1720
    • The best code is the DNA of the hops.
      • View Profile
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #53 on: December 25, 2018, 05:20:22 pm »
  • Best Answer
  • Thank you Steve, but i need it not. My source which is added here in ZIP file works fine, but it is not too user friendly (but mainly that he is doing what he has)

    Sorry, I realized a fatal bug in concept in my proposal. Therefore, I will review and embed the new program to embed multiple files into the EXE in my own thread.
    « Last Edit: December 26, 2018, 05:16:13 am by Petr »

    Offline TempodiBasic

    • Forum Resident
    • Posts: 1792
      • View Profile
    Re: 'Tis the season, AGAIN! - Xmas contest
    « Reply #54 on: December 25, 2018, 05:48:04 pm »
  • Best Answer
  • Happy Christmas

    @Pete
    Quote
    Let me guess. If you open it up it says...

    Money's short
    Times are hard
    Here's your QB
    Christmas card!

    Pete :D

    Just like that, yeah :-)
    but in yours there is rhyme ;-)
    Programming isn't difficult, only it's  consuming time and coffee