Author Topic: Scrolling Plasma Lines the Movie  (Read 3533 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Scrolling Plasma Lines the Movie
« on: October 09, 2019, 11:25:11 pm »
Code: QB64: [Select]
  1. _TITLE "Scrolling Plasma Lines Mod 1" 'B+ 2019-10-09
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. DIM ln(0 TO ymax) AS _UNSIGNED LONG
  6.  
  7. r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  8. f = xmax / ymax
  9.     IF RND < .01 THEN r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  10.     FOR i = UBOUND(ln) - 1 TO 0 STEP -1
  11.         ln(i + 1) = ln(i)
  12.         LINE (0, i)-STEP(xmax, 0), ln(i + 1)
  13.         LINE (xmax - i * f, 0)-STEP(0, ymax), ln(i + 1)
  14.         LINE (i * f, 0)-STEP(f, ymax), ln(i + 1)
  15.         LINE (0, ymax - i)-STEP(xmax, 0), ln(i + 1)
  16.     NEXT
  17.     ln(0) = _RGB32(127 + 127 * SIN(r * c), 127 + 127 * SIN(g * c), 127 + 127 * SIN(b * c), 40)
  18.     c = c + 1
  19.     _DISPLAY
  20.     _LIMIT 60
  21.  

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Scrolling Plasma Lines the Movie
« Reply #1 on: October 10, 2019, 03:36:48 am »
Half expecting a Scotsman and his bagpipes! Very cool...
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Scrolling Plasma Lines the Movie
« Reply #2 on: October 10, 2019, 06:20:26 am »
That's some really CPU intensive work going on inside that inner FOR loop there!

Code: QB64: [Select]
  1. _TITLE "Scrolling Plasma Lines Mod 1" 'B+ 2019-10-09
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. DIM ln(0 TO ymax) AS _UNSIGNED LONG
  6.  
  7. r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  8. f = xmax / ymax
  9.     FPS = FPS + 1
  10.     IF RND < .01 THEN r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  11.     FOR i = UBOUND(ln) - 1 TO 0 STEP -1
  12.         ln(i + 1) = ln(i)
  13.         LINE (0, i)-STEP(xmax, 0), ln(i + 1)
  14.         LINE (xmax - i * f, 0)-STEP(0, ymax), ln(i + 1)
  15.         LINE (i * f, 0)-STEP(f, ymax), ln(i + 1)
  16.         LINE (0, ymax - i)-STEP(xmax, 0), ln(i + 1)
  17.     NEXT
  18.     ln(0) = _RGB32(127 + 127 * SIN(r * c), 127 + 127 * SIN(g * c), 127 + 127 * SIN(b * c), 40)
  19.     c = c + 1
  20.     LOCATE 1, 1: PRINT FPSDisplay
  21.     _DISPLAY
  22.     _LIMIT 60
  23.     IF TIMER > T# + 1 THEN FPSDisplay = FPS: FPS = 0: T# = TIMER

As this little program runs for a bit, my CPU fans turn on and imitate an airplane engine, with a single core's usage going up to nearly 100%!  Once it hits its stride, my PC produces only about 27 or 28 FPS with this little demo, rendering that _LIMIT 60 completely moot.  It can't slow down my PC to make it run at 60 FPS, since it won't even run at 30 FPS to begin with!
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Scrolling Plasma Lines the Movie
« Reply #3 on: October 10, 2019, 06:37:13 am »
Just having fun with this a bit, here's a mod which implements a step variable for the routine, which changes the patterns slightly.  When the stepper gets to 7, the screen ends up amazing stable and unchanging after a second or so for me, which I found rather oddish.

Code: QB64: [Select]
  1. _TITLE "Scrolling Plasma Lines Mod 1s (S for STEVE)" 'B+ 2019-10-09
  2. CONST xmax = 800, ymax = 600
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. DIM ln(0 TO ymax) AS _UNSIGNED LONG
  6.  
  7. r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  8. f = xmax / ymax
  9. stepper = 1
  10.     FPS = FPS + 1
  11.     IF RND < .01 THEN r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  12.     FOR i = UBOUND(ln) - stepper TO 0 STEP -stepper
  13.         ln(i + stepper) = ln(i)
  14.         LINE (0, i)-STEP(xmax, 0), ln(i + stepper)
  15.         LINE (xmax - i * f, 0)-STEP(0, ymax), ln(i + stepper)
  16.         LINE (i * f, 0)-STEP(f, ymax), ln(i + stepper)
  17.         LINE (0, ymax - i)-STEP(xmax, 0), ln(i + stepper)
  18.     NEXT
  19.     ln(0) = _RGB32(127 + 127 * SIN(r * c), 127 + 127 * SIN(g * c), 127 + 127 * SIN(b * c), 40)
  20.     c = c + stepper
  21.     LOCATE 1, 1: PRINT FPSDisplay, stepper
  22.     _DISPLAY
  23.     _LIMIT 120
  24.     IF TIMER > T# + 1 THEN FPSDisplay = FPS: FPS = 0: T# = TIMER: SecondsRun = SecondsRun + 1
  25.     IF SecondsRun MOD 10 = 0 THEN CLS: SecondsRun = 1: stepper = stepper + 1
  26.  
  27.  
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: Scrolling Plasma Lines the Movie
« Reply #4 on: October 10, 2019, 10:10:12 am »
Well we can speed it up like this but Full Screen sucks!!!
Code: QB64: [Select]
  1. _TITLE "Scrolling Plasma Lines Mod 1" 'B+ 2019-10-09
  2. CONST xmax = 400, ymax = 300
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 300, 40
  5. _FULLSCREEN '<<<<  YUCK!!!!!!!!!!!
  6. DIM ln(0 TO ymax) AS _UNSIGNED LONG
  7.  
  8. r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  9. f = xmax / ymax
  10. WHILE _KEYDOWN(27) = 0
  11.     FPS = FPS + 1
  12.     IF RND < .01 THEN r = RND ^ 2: g = RND ^ 2: b = RND ^ 2
  13.     FOR i = UBOUND(ln) - 1 TO 0 STEP -1
  14.         ln(i + 1) = ln(i)
  15.         LINE (0, i)-STEP(xmax, 0), ln(i + 1)
  16.         LINE (xmax - i * f, 0)-STEP(0, ymax), ln(i + 1)
  17.         LINE (i * f, 0)-STEP(f, ymax), ln(i + 1)
  18.         LINE (0, ymax - i)-STEP(xmax, 0), ln(i + 1)
  19.     NEXT
  20.     ln(0) = _RGB32(127 + 127 * SIN(r * c), 127 + 127 * SIN(g * c), 127 + 127 * SIN(b * c), 40)
  21.     c = c + 1
  22.     LOCATE 1, 1: PRINT FPSDisplay
  23.     _DISPLAY
  24.     '_LIMIT 60
  25.     IF TIMER > T# + 1 THEN FPSDisplay = FPS: FPS = 0: T# = TIMER
  26.  
  27.