QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: krovit on February 15, 2020, 06:00:40 am

Title: Flashing text: how to do it?
Post by: krovit 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.  

Title: Re: Flashing text: how to do it?
Post by: Real2Two on February 15, 2020, 06:01:33 am
What do you mean flashing text? Text constantly changing color/black and white?
Title: Re: Flashing text: how to do it?
Post by: krovit 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.

Title: Re: Flashing text: how to do it?
Post by: Real2Two 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.
Title: Re: Flashing text: how to do it?
Post by: krovit on February 15, 2020, 06:39:02 am
Thank you,

but nothing happens...
on your monitor instead?
Title: Re: Flashing text: how to do it?
Post by: Real2Two on February 15, 2020, 06:39:35 am
Is the screen just black?
Title: Re: Flashing text: how to do it?
Post by: krovit 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)
Title: Re: Flashing text: how to do it?
Post by: Real2Two 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
Title: Re: Flashing text: how to do it?
Post by: krovit on February 15, 2020, 06:43:47 am
Great!
Every now and then I get lost in a glass of water
Title: Re: Flashing text: how to do it?
Post by: Real2Two on February 15, 2020, 06:44:02 am
Worked? _LIMIT was always confusing to me.

SLEEP, _DELAY, _LIMIT... all so different
Title: Re: Flashing text: how to do it?
Post by: krovit 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.
Title: Re: Flashing text: how to do it?
Post by: FellippeHeitor 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).
Title: Re: Flashing text: how to do it?
Post by: Pete 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
Title: Re: Flashing text: how to do it?
Post by: bplus 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.