Author Topic: Stars w/ Time Screensaver  (Read 958 times)

0 Members and 1 Guest are viewing this topic.

Offline CloudZimmermann

  • Newbie
  • Posts: 4
    • View Profile
Stars w/ Time Screensaver
« on: May 15, 2020, 03:11:36 pm »
Program: Stars w/ Time Screensaver
Creator:  Cloud Zimmermann
Date:      1/7/2020

Code: QB64: [Select]
  1. ' Program: Stars w/ Time
  2. ' Creator: Cloud Zimmermann
  3. ' Created: 1/7/2020
  4.  
  5. DECLARE SUB DrawDigit (d AS INTEGER, p AS INTEGER, x AS INTEGER, y AS INTEGER)
  6. DECLARE SUB DrawClock (clock AS ANY)
  7. SCREEN 7, 0, 0, 1
  8.  
  9. quit% = 0
  10.  
  11. TYPE StarType
  12.     x AS INTEGER
  13.     y AS INTEGER
  14.     z AS INTEGER
  15.     c AS INTEGER
  16.  
  17. TYPE ClockType
  18.     x AS INTEGER
  19.     y AS INTEGER
  20.     t AS STRING * 12
  21.     c AS INTEGER
  22.     dx AS INTEGER
  23.     dy AS INTEGER
  24.  
  25. DIM clock AS ClockType
  26. clock.x = 5
  27. clock.y = 5
  28. clock.c = 8
  29. clock.dx = 1
  30. clock.dy = 1
  31.  
  32. count% = 30
  33.  
  34. DIM Star(1 TO count%) AS StarType
  35.  
  36. FOR i% = 1 TO count%
  37.     Star(i%).x = INT(RND * 320) + 1
  38.     Star(i%).y = INT(RND * 200) + 1
  39.     Star(i%).z = INT(RND * 4) + INT(RND * 1) + 1
  40.     Star(i%).c = INT(RND * 16) + 1
  41. NEXT i%
  42.  
  43.  
  44.  
  45. WHILE quit% = 0
  46.     CLS
  47.     IF INKEY$ <> "" THEN quit% = 1
  48.  
  49.     FOR i% = 1 TO count%
  50.         Star(i%).y = Star(i%).y + Star(i%).z
  51.         PSET (Star(i%).x, Star(i%).y), Star(i%).c
  52.         IF Star(i%).y > 200 THEN Star(i%).y = Star(i%).y - 200
  53.     NEXT i%
  54.  
  55.     'LOCATE 5, 5: COLOR 3
  56.     'PRINT TIME$
  57.  
  58.     CALL DrawClock(clock)
  59.  
  60.     PCOPY 0, 1
  61.     _LIMIT 60
  62.  
  63.  
  64. SUB DrawClock (clock AS ClockType)
  65.     clock.x = clock.x + clock.dx
  66.     clock.y = clock.y + clock.dy
  67.  
  68.     tmp$ = TIME$
  69.     FOR pointer% = 1 TO LEN(tmp$)
  70.         digit% = VAL(MID$(tmp$, pointer%, 1))
  71.         CALL DrawDigit(digit%, pointer%, clock.x, clock.y)
  72.     NEXT pointer%
  73.  
  74.     'PSET (clock.x, clock.y), clock.c
  75.  
  76.     IF clock.x <= 0 OR clock.x >= 320 - 46 THEN clock.dx = -clock.dx
  77.     IF clock.y <= 0 OR clock.y >= 200 - 6 THEN clock.dy = -clock.dy
  78.  
  79. SUB DrawDigit (d AS INTEGER, p AS INTEGER, x AS INTEGER, y AS INTEGER)
  80.     tmp$ = "BC11M" + STR$(x) + "," + STR$(y) + " BM+" + STR$(5 * p) + ",0"
  81.     IF d = 1 THEN tmp$ = tmp$ + "BM+3,0D4"
  82.     IF d = 2 THEN tmp$ = tmp$ + "R3D2L3D2R3"
  83.     IF d = 3 THEN tmp$ = tmp$ + "R3D2L3R3D2L3"
  84.     IF d = 4 THEN tmp$ = tmp$ + "D2R3U2D4"
  85.     IF d = 5 THEN tmp$ = tmp$ + "BM+3,0L3D2R3D2L3"
  86.     IF d = 6 THEN tmp$ = tmp$ + "BM+3,0L3D4R3U2L3"
  87.     IF d = 7 THEN tmp$ = tmp$ + "R3D4"
  88.     IF d = 8 THEN tmp$ = tmp$ + "R3D4L3U4D2R3"
  89.     IF d = 9 THEN tmp$ = tmp$ + "R3L3D2R3U2D4"
  90.     IF d = 0 THEN tmp$ = tmp$ + "R3D4L3U4"
  91.     DRAW tmp$
  92.  
* STARS.exe (Filesize: 1.99 MB, Downloads: 94)
* STARS.BAS (Filesize: 2.28 KB, Downloads: 113)

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Stars w/ Time Screensaver
« Reply #1 on: May 15, 2020, 08:39:40 pm »
Why are all the stars falling? 
Is it the end of the Universe? 
And why do they have so many colors?
Are they going to a costume party?

The clock needs to be a little bigger before a cat will chase it.

It works better if you plug it in.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Stars w/ Time Screensaver
« Reply #2 on: May 16, 2020, 11:32:46 am »
Pretty neat!

Have you given any thought to maybe giving random values to the clocks movement so it goes faster or slower around the screen?  And you know if you made the 'stars' shades of blue it would look like rain! and you could add random flashes like lightning! Could call it the "Rainy Day Screen Saver"!
Granted after becoming radioactive I only have a half-life!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Stars w/ Time Screensaver
« Reply #3 on: May 16, 2020, 01:30:14 pm »
well went ahead and mocked it up.

hope you don't mind too much. Commented most everything I changed and did.

Code: QB64: [Select]
  1. ' Program: Stars w/ Time
  2. ' Creator: Cloud Zimmermann
  3. ' Created: 1/7/2020
  4.  
  5. 'slight modification by Cobalt on 5/16/2020 to make it a rainy day. everything but the lightning :-(
  6.  
  7. DECLARE SUB DrawDigit (d AS INTEGER, p AS INTEGER, x AS INTEGER, y AS INTEGER)
  8. DECLARE SUB DrawClock (clock AS ANY)
  9. 'SCREEN 7, 0, 0, 1
  10.  
  11. 'lets cover the basics!
  12. CONST TRUE = -1, FALSE = NOT TRUE
  13. 'lets make the screen a little bigger and give ourselves more color room.
  14. SCREEN _NEWIMAGE(640, 480, 32)
  15.  
  16. 'make a temp layer to draw upon, to simulate screen 7 layers
  17. Temp& = _NEWIMAGE(640, 480, 32)
  18.  
  19. _DELAY .1 'wait a moment for screen to materialize!
  20. _TITLE "Rainy Day Screen Saver!"
  21.  
  22. 'move this here to cover new random items
  23.  
  24. quit% = 0
  25.  
  26. 'swapping our variable types to allow for more variation
  27. TYPE StarType
  28.  
  29. TYPE ClockType
  30.  t AS STRING * 12
  31.  dx AS SINGLE
  32.  dy AS SINGLE
  33.  
  34.  
  35. DIM clock AS ClockType
  36. 'lets allow the clock to start in other locations
  37. clock.x = INT(RND * 550) + 5
  38. clock.y = INT(RND * 460) + 5
  39. clock.c = _RGB32(192) '8
  40. clock.dx = RND * 3 + .75
  41. clock.dy = RND * 3 + .75
  42.  
  43.  
  44.  
  45. 'add a bit of variance to our rainy day(increased base to help with larger screen area)
  46. count% = INT(RND * 175) + 75
  47.  
  48. DIM Star(1 TO count%) AS StarType
  49.  
  50. FOR i% = 1 TO count%
  51.  Star(i%).x = INT(RND * 640) + 1
  52.  Star(i%).y = INT(RND * 480) + 1
  53.  Star(i%).z = (RND * 2.5)
  54.  'make the rain shades of blue(brightened a bit to make it easier to see).
  55.  Star(i%).c = _RGB32(16, INT(RND * 80) + 32, (32 + INT(Star(i%).z * 96)) + 48)
  56. NEXT i%
  57.  
  58. _DEST Temp& 'draw everything to the temp layer( like screen 7's layer 1)
  59.  
  60. COLOR clock.c
  61.  
  62. WHILE quit% = 0
  63.  CLS
  64.  IF INKEY$ <> "" THEN quit% = 1
  65.  
  66.  FOR i% = 1 TO count%
  67.   Star(i%).y = Star(i%).y + Star(i%).z
  68.   Star(i%).z = Star(i%).z * 1.05
  69.   PSET (Star(i%).x, Star(i%).y), Star(i%).c
  70.   'resetting the drops height when it reaches the "ground" and vary its velocity
  71.   'and move the drop to a new x location
  72.   IF Star(i%).y > 480 THEN Star(i%).y = Star(i%).y - 480: Star(i%).z = (RND * 2.5): Star(i%).x = INT(RND * 640) + 1
  73.  
  74.  
  75.  NEXT i%
  76.  
  77.  'LOCATE 5, 5: COLOR 3
  78.  'PRINT TIME$
  79.  
  80.  DrawClock clock 'don't need CALL anymore
  81.  ' PCOPY 0, 1
  82.  _PUTIMAGE , Temp&, _DISPLAY 'lets PCOPY the temp layer to our display
  83.  CLS
  84.  _LIMIT 60
  85.  '_DELAY .5
  86.  
  87. SUB DrawClock (clock AS ClockType)
  88.  STATIC X_Flag%%, Y_Flag%%
  89.  ' tmp$ = TIME$
  90.  ' FOR pointer% = 1 TO LEN(tmp$)
  91.  '  digit% = VAL(MID$(tmp$, pointer%, 1))
  92.  ' CALL DrawDigit(digit%, pointer%, clock.x, clock.y)
  93.  ' NEXT pointer%
  94.  
  95.  DrawTime clock.x, clock.y 'not as clever as DrawDigit, but very simple
  96.  
  97.  'PSET (clock.x, clock.y), clock.c
  98.  
  99.  'simple!
  100.  'clock.x = clock.x + clock.dx
  101.  'clock.y = clock.y + clock.dy
  102.  'IF clock.x <= 0 OR clock.x >= 640 - 64 THEN clock.dx = -clock.dx
  103.  'IF clock.y <= 0 OR clock.y >= 480 - 12 THEN clock.dy = -clock.dy
  104.  
  105.  'not so simple
  106.  IF clock.x <= 2 THEN X_Flag%% = FALSE: clock.dx = RND * 3 + .5
  107.  IF clock.x >= 640 - 64 THEN X_Flag%% = TRUE: clock.dx = RND * 3 + .5
  108.  IF clock.y <= 2 THEN Y_Flag%% = FALSE: clock.dy = RND * 3 + .5
  109.  IF clock.y >= 480 - 12 THEN Y_Flag%% = TRUE: clock.dy = RND * 3 + .5
  110.  IF X_Flag%% = TRUE THEN clock.x = clock.x - clock.dx ELSE clock.x = clock.x + clock.dx
  111.  IF Y_Flag%% = TRUE THEN clock.y = clock.y - clock.dy ELSE clock.y = clock.y + clock.dy
  112.  
  113.  
  114. SUB DrawDigit (d AS INTEGER, p AS INTEGER, x AS INTEGER, y AS INTEGER)
  115.  TimeColor~& = _RGB32(0, 112, 192) 'now using 32bit colors we need to make our clock color
  116.  'only thing missing is the `:`? Numbers look really good, I think anyway!
  117.  tmp$ = "BC" + STR$(TimeColor~&) + "M" + STR$(x) + "," + STR$(y) + " BM+" + STR$(5 * p) + ",0"
  118.  IF d = 1 THEN tmp$ = tmp$ + "BM+3,0D4"
  119.  IF d = 2 THEN tmp$ = tmp$ + "R3D2L3D2R3"
  120.  IF d = 3 THEN tmp$ = tmp$ + "R3D2L3R3D2L3"
  121.  IF d = 4 THEN tmp$ = tmp$ + "D2R3U2D4"
  122.  IF d = 5 THEN tmp$ = tmp$ + "BM+3,0L3D2R3D2L3"
  123.  IF d = 6 THEN tmp$ = tmp$ + "BM+3,0L3D4R3U2L3"
  124.  IF d = 7 THEN tmp$ = tmp$ + "R3D4"
  125.  IF d = 8 THEN tmp$ = tmp$ + "R3D4L3U4D2R3"
  126.  IF d = 9 THEN tmp$ = tmp$ + "R3L3D2R3U2D4"
  127.  IF d = 0 THEN tmp$ = tmp$ + "R3D4L3U4"
  128.  DRAW tmp$
  129.  
  130. SUB DrawTime (X!, Y!)
  131.  _PRINTSTRING (X!, Y!), TIME$
Granted after becoming radioactive I only have a half-life!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Stars w/ Time Screensaver
« Reply #4 on: May 16, 2020, 05:20:36 pm »
The sky is falling!  The sky is falling!  - Chicken Little
It works better if you plug it in.