Author Topic: A rank amateur blinks...  (Read 4308 times)

0 Members and 1 Guest are viewing this topic.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
A rank amateur blinks...
« on: September 11, 2018, 07:51:25 pm »
When I was working in SCREEN 0, I would often make use of blinking colors to attract the users attention. They would certainly do that, but I found the mode's blink algorithm to be too strident and wished for something a bit more subtle.

Here's what my amateur skills came up with. Let me know what you think of my solution and if it can be improved upon.

Code: QB64: [Select]
  1. blink_a& = _RGB32(183, 50, 183)
  2. blink_b& = _RGB32(183, 100, 183)
  3. normal& = _RGB32(252, 252, 252)
  4. s% = 60
  5. disp& = _NEWIMAGE(640, 400, 32)
  6. SCREEN disp&
  7. _DEST disp&
  8.     x$ = INKEY$
  9.     IF x$ <> "" THEN x = VAL(x$)
  10.     COLOR blink_a&
  11.     LOCATE 5, 5
  12.     msg$ = "Press 7 to stop this infernally stupid demo."
  13.     FOR a = 1 TO LEN(msg$)
  14.         IF a MOD 2 = 0 THEN
  15.             COLOR blink_a&
  16.         ELSE
  17.             COLOR blink_b&
  18.         END IF
  19.         PRINT MID$(msg$, a, 1);
  20.     NEXT a
  21.     y = y + 1
  22.     IF y MOD (s% / 4) = 0 THEN
  23.         y = 0
  24.         SWAP blink_a&, blink_b&
  25.     END IF
  26.  
  27.     _LIMIT s%
  28. LOOP UNTIL x = 7
  29. COLOR normal&
  30.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: A rank amateur blinks...
« Reply #1 on: September 11, 2018, 08:15:13 pm »
Well it works. I'd suggest taking the msg variable out of the loop, because it only needs to be assigned once. It doesn't hurt having it the way it is, it just doesn't need repeating, like a lot of things in life, it's good if you just hear it once, you don't need to hear it over and over, or re-iterated by others, or written on some handy reminder that has some defect in the glue base so no matter how hard you try to scrape it off, it just stays there... and stays there... and stays there.Other than that, good job!

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

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A rank amateur blinks...
« Reply #2 on: September 11, 2018, 08:22:06 pm »
How about a NOT color?

SCREEN _NEWIMAGE(640,480,32)
BlinkRed = _RGB32(255,0,0)
DO
    CLS
    _LIMIT 2 'Just for the demo
    BlinkRed = NOT BlinkRed
    COLOR BlinkRed
     PRINT "Hello World"
    _DISPLAY
LOOP UNTIL _KEYHIT

******************

Though honestly, I'd suggest for 32-bit color modes to use 2 separate screens and then swap displays to simulate the blink.  Then, you could have normal text at one part of the screen, "blink" text at another part, and all you'd need to do is toggle between which screen to display every half second or so.
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: A rank amateur blinks...
« Reply #3 on: September 11, 2018, 09:21:07 pm »
How about a blink'in beat?
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(220, 50, 32)
  2. WHILE _KEYDOWN(27) = 0
  3.     CLS
  4.     lc = lc + _PI(1 / 16)
  5.     b = b + 1
  6.     c = (c + 1) MOD 6
  7.     IF b THEN _PRINTSTRING (65, 15), "Hello"
  8.     IF c THEN _PRINTSTRING (118, 15), "World"
  9.     _DISPLAY
  10.     _LIMIT INT(5 * SIN(lc) + 6)
  11.  
  12.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: A rank amateur blinks...
« Reply #4 on: September 11, 2018, 10:00:27 pm »
How about a blink'in beat?


That was cool.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: A rank amateur blinks...
« Reply #5 on: September 11, 2018, 10:04:53 pm »
Well it works. I'd suggest taking the msg variable out of the loop, because it only needs to be assigned once.

Good point, I also noticed after posting it that the first 'COLOR blink_a&' in the loop was completely redundant.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: A rank amateur blinks...
« Reply #6 on: September 11, 2018, 10:08:43 pm »
Though honestly, I'd suggest for 32-bit color modes to use 2 separate screens and then swap displays to simulate the blink.  Then, you could have normal text at one part of the screen, "blink" text at another part, and all you'd need to do is toggle between which screen to display every half second or so.

That's probably where I need to be, I just have to get on top of the learning curve. I'm playing with 32 bit, but still approaching it with SCREEN 0 thinking.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A rank amateur blinks...
« Reply #7 on: September 11, 2018, 10:19:37 pm »
Hi OldMoses,

I liked the color swap blinking, it's less obnoxious. Here is a rolling color "blink":
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(220, 50, 32)
  2. CONST H$ = "Hello World"
  3. DIM SHARED r&, g&, b&, old&, new&
  4. update
  5. WHILE _KEYDOWN(27) = 0
  6.     IF RND < 1 / 20 AND m = 10 THEN update
  7.     CLS
  8.     m = (m + 1) MOD 11
  9.     IF m = 0 THEN SWAP old&, new&
  10.     x = 65 + m * 8
  11.     COLOR old&
  12.     _PRINTSTRING (65, 15), MID$(H$, 1, m)
  13.     COLOR new&
  14.     _PRINTSTRING (x, 15), MID$(H$, m + 1)
  15.     _DISPLAY
  16.     _LIMIT 30
  17.  
  18. SUB update
  19.     r& = RND * 255: g& = RND * 255: b& = RND * 255
  20.     old& = _RGB32(r&, g&, b&)
  21.     new& = _RGB32((r& + 128) MOD 255, (g& + 128) MOD 255, (b& + 128) MOD 255)
  22.  
  23.  

Edit: Better color scheme
« Last Edit: September 11, 2018, 10:44:04 pm by bplus »