Author Topic: Flashing text: how to do it?  (Read 4750 times)

0 Members and 1 Guest are viewing this topic.

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Flashing text: how to do it?
« on: February 15, 2020, 06:00:40 am »
I've never really understood how _LIMIT and _DISPLAY works but I think it's useful in case you want to create a flashing text.

For example: how to make the flashing text ?

Code: QB64: [Select]
  1.  
  2.     LOCATE 10,1: print "Text"
  3.  
  4.  

Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline Real2Two

  • Newbie
  • Posts: 18
    • View Profile
Re: Flashing text: how to do it?
« Reply #1 on: February 15, 2020, 06:01:33 am »
What do you mean flashing text? Text constantly changing color/black and white?

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: Flashing text: how to do it?
« Reply #2 on: February 15, 2020, 06:07:03 am »
Yes, or red and white etc.

Important information that I had forgotten to specify:
the screen is in SCREEN _NEWIMAGE(pixelx,pixely,32) and not usually SCREEN MODE (which is not specified anyway).

I think then the proposed code should simulate the flashing by entering the appropriate commands _LIMIT, _DISPALY, COLOR, etc.

« Last Edit: February 15, 2020, 06:12:11 am by krovit »
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline Real2Two

  • Newbie
  • Posts: 18
    • View Profile
Re: Flashing text: how to do it?
« Reply #3 on: February 15, 2020, 06:30:45 am »
Something like:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(300, 500, 32)
  2.  
  3. colornum = 0
  4.  
  5. IF colornum = 0 THEN
  6. colornum = 1
  7. COLOR &HFFffffff
  8. colornum = 0
  9. COLOR &HFF000000
  10. LOCATE 10, 1: PRINT "test"
  11. SYSTEM ' Not required.
« Last Edit: February 15, 2020, 06:38:26 am by Real2Two »

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: Flashing text: how to do it?
« Reply #4 on: February 15, 2020, 06:39:02 am »
Thank you,

but nothing happens...
on your monitor instead?
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline Real2Two

  • Newbie
  • Posts: 18
    • View Profile
Re: Flashing text: how to do it?
« Reply #5 on: February 15, 2020, 06:39:35 am »
Is the screen just black?

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: Flashing text: how to do it?
« Reply #6 on: February 15, 2020, 06:40:32 am »
only white, stable text, and intercepts ESC late (but this is perhaps obvious given the statement _DELAY 10)
« Last Edit: February 15, 2020, 06:42:21 am by krovit »
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline Real2Two

  • Newbie
  • Posts: 18
    • View Profile
Re: Flashing text: how to do it?
« Reply #7 on: February 15, 2020, 06:41:21 am »
Try this:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(300, 500, 32)
  2.  
  3. colornum = 0
  4.  
  5. IF colornum = 0 THEN
  6. colornum = 1
  7. COLOR &HFFffffff
  8. colornum = 0
  9. COLOR &HFF000000
  10. LOCATE 10, 1: PRINT "test"
  11. SYSTEM ' Not required.

Also try adjusting _LIMIT

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: Flashing text: how to do it?
« Reply #8 on: February 15, 2020, 06:43:47 am »
Great!
Every now and then I get lost in a glass of water
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

Offline Real2Two

  • Newbie
  • Posts: 18
    • View Profile
Re: Flashing text: how to do it?
« Reply #9 on: February 15, 2020, 06:44:02 am »
Worked? _LIMIT was always confusing to me.

SLEEP, _DELAY, _LIMIT... all so different

Offline krovit

  • Forum Regular
  • Posts: 179
    • View Profile
Re: Flashing text: how to do it?
« Reply #10 on: February 15, 2020, 06:47:36 am »
Me too!
Anyway now I'll see how to adapt it. I would like it to flash for a moment to warn me of something.
Nothing is easy, especially when it appears simple (and nothing could be as dangerous as trying to do good to others)

FellippeHeitor

  • Guest
Re: Flashing text: how to do it?
« Reply #11 on: February 15, 2020, 09:49:26 am »
If you're working with SCREEN 0 (text mode), then there's native blinking, as long as you use colors above index 15. To make it simple, use colors 1-15 as you would but add 16 when you want it to blink:

Code: QB64: [Select]
  1. CONST BlinkFactor = 16
  2. PRINT "This is bright white;"
  3. COLOR 15 + BlinkFactor
  4. PRINT "This is bright white, but blinking."
  5. PRINT "This is red;"
  6. COLOR 4 + BlinkFactor
  7. PRINT "This is red, but blinking."

If you use _BLINK OFF, then blinking gets replaced with high-intensity background colors.

If you use _DISPLAY, blinking gets disabled.

Again, this is only for text mode (SCREEN 0).

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Flashing text: how to do it?
« Reply #12 on: February 15, 2020, 10:26:16 am »
Darn it, late to the party again! Yep, QBasic had built-in blinking for SCREEN 0... the only screen anyone needs.

Oh well, if we could just get QB64 to have a native blinking cursor in graphics mode, that would be nice. Who knows and maybe it has by now, but a long time ago, in QB, I had to make a cursor blinking routine for what few graphics programs I put together.

Pete
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: Flashing text: how to do it?
« Reply #13 on: February 15, 2020, 11:32:35 am »
Here is a handy sub that allows allot more than just blinking text!
Demos _DISPLAY to prevent unwanted blinking and _LIMIT to control the maximum frames per second to show in loop.
Code: QB64: [Select]
  1. _TITLE "Blinking and more with text string" 'b+ 2020-02-15
  2.  
  3. '===================================================================================
  4. ' Lets blink between colors white and blue, expanding and shrinking text for 10 secs
  5. '===================================================================================
  6.  
  7. s$ = "Blink colors white and blue, expanding and shrinking centered text for 10 secs"
  8. SCREEN _NEWIMAGE(800, 600, 32)
  9. th = 16 'Text Height - start normal
  10. dh = 1  'change height
  11. flashTimes = 100 'with limit 10 this will take 10 times a second and be done in 100/10 secs
  12. start$ = TIME$
  13. WHILE _KEYDOWN(27) = 0
  14.     CLS
  15.     PRINT start$; ", ";
  16.     IF flashTimes THEN
  17.         IF toggle = 1 THEN C~& = &HFFFFFFFF ELSE C~& = &HFF0000FF
  18.         cText _WIDTH / 2, _HEIGHT / 2, th, C~&, s$
  19.         toggle = 1 - toggle
  20.         th = th + dh
  21.         IF th > 64 THEN th = 64: dh = -dh
  22.         IF th < 6 THEN th = 6: dh = -dh
  23.         flashTimes = flashTimes - 1
  24.         lastFlash$ = TIME$
  25.     ELSE
  26.         cText _WIDTH / 2, _HEIGHT / 2, 16, &HFFFFFF00, s$
  27.     END IF
  28.     PRINT lastFlash$; " <<<< notice these numbers are not flashing even though we CLS every frame"
  29.     _DISPLAY '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> eliminates blinking screens when use CLS
  30.     _LIMIT 10 '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  allows maximum number of loops of 10 per sec
  31.  
  32. 'center the text at x, y with given height and color
  33. SUB cText (x, y, textHeight, K AS _UNSIGNED LONG, txt$)
  34.     DIM fg AS _UNSIGNED LONG, cur&, I&, mult, xlen
  35.     fg = _DEFAULTCOLOR
  36.     'screen snapshot
  37.     cur& = _DEST
  38.     I& = _NEWIMAGE(8 * LEN(txt$), 16, 32)
  39.     _DEST I&
  40.     COLOR K, _RGBA32(0, 0, 0, 0)
  41.     _PRINTSTRING (0, 0), txt$
  42.     mult = textHeight / 16
  43.     xlen = LEN(txt$) * 8 * mult
  44.     _PUTIMAGE (x - .5 * xlen, y - .5 * textHeight)-STEP(xlen, textHeight), I&, cur&
  45.     COLOR fg
  46.     _FREEIMAGE I&
  47.  
« Last Edit: February 15, 2020, 11:57:42 am by bplus »