Author Topic: Please STOP kidding me with CONST!  (Read 3655 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Please STOP kidding me with CONST!
« on: September 30, 2019, 06:06:05 pm »
Hi
It is real another thread about CONST and 32bit colors...

I must sign as BAD PRACTICE to create CONST colors for 32bit screens!  :-)

Or just do you developers like to kidding me with this keywords? :-P

here the issue

try to run to see the result
Code: QB64: [Select]
  1. CONST True = -1, False = NOT True, Opaque = 255, HalfOpa = 127, QuaterOpac = 63
  2. ' Opaque colors
  3. CONST Black = _RGBA32(0, 0, 0, Opaque)
  4. CONST Green = _RGBA32(50, 200, 50, Opaque)
  5. CONST Blu = _RGBA32(50, 50, 250, Opaque)
  6. CONST White = _RGBA32(250, 250, 250, Opaque)
  7. 'Half Opaque colors
  8. CONST HBlack = _RGBA32(0, 0, 0, HalfOpa)
  9. CONST HGreen = _RGBA32(50, 200, 50, HalfOpa)
  10. CONST HBlu = _RGBA32(50, 50, 250, HalfOpa)
  11. CONST HRed = _RGBA32(250, 50, 50, HalfOpa)
  12. CONST HWhite = _RGBA32(250, 250, 250, HalfOpa)
  13. ' Quarter Opaque colors
  14. CONST QBlack = _RGBA32(0, 0, 0, QuaterOpac)
  15. CONST QGreen = _RGBA32(50, 200, 50, QuaterOpac)
  16. CONST QBlu = _RGBA32(50, 50, 250, QuaterOpac)
  17. CONST QRed = _RGBA32(250, 50, 50, QuaterOpac)
  18. CONST QWhite = _RGBA32(250, 250, 250, QuaterOpac)
  19.  
  20. SCREEN _NEWIMAGE(800, 600, 32)
  21.  
  22. FOR a = 1 TO 10
  23.     b = (RND * 50) + 1
  24.     c = (RND * 50) + 1
  25.     DrawCell b, c, HGreen
  26.     DrawCell b, c, HBlu
  27.     DrawCell b, c, HRed
  28.  
  29. SUB DrawCell (X AS INTEGER, Y AS INTEGER, Col AS LONG)
  30.     LINE (10 * (X - 1), 10 * (Y - 1))-(10 * X, 10 * Y), Col, BF
  31.     LINE (10 * (X - 1), 10 * (Y - 1))-(10 * X, 10 * Y), White, B
  32.  

well you'll get a black screen! Yes!
Why? Because _RGBA32 doesn't get the value of an Integer Constant defined first in the program!
LOL, you want that I come back to ASCII screen! I have understood this!

Thanks for read!
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Please STOP kidding me with CONST!
« Reply #1 on: September 30, 2019, 07:11:05 pm »
CONST has always been half implemented in QB64, with a lot of things just not possible.  It wasn’t very long ago when a CONST couldn’t even process another CONST at all.  (I think v1.2 or v1.3 is when the functionality was added.)  If it doesn’t work with _RGB, it’s simply an oversight where those commands are processed differently than the main segment of Math Functions (they offer a color picker pop-up now, I think). 

Here’s what you need to do to fix the issue:

1) Relax.  Repeat, repeatedly, “Nobody is out to get me, or sabotage my efforts coding with CONST and colors.”  Breath long, deep breaths.  Inhale.  Exhale.  Repeat, repeatedly, “Nobody is out to get me, or sabotage my efforts coding with CONST and colors.”   Then...
2) Work around the issue by placing literal values in the function.
3) OR, learn to write color values as their hex equivalent. 
4) OR, go into QB64.bas, scroll down to the label “stevewashere:”, and just a short ways after that — past the $PRECOMPILER commands — you’ll see “CONST” and the two _RGB and _RGBA areas.  Correct the issue yourself and share the results with us.
5) OR, simply post a bug report and wait until somebody decides to look into the issue and add the functionality there.

Either that, or take Pete’s recommended method:
6) Just code in SCREEN 0, where you don’t need no complicated CONST for colors.
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: Please STOP kidding me with CONST!
« Reply #2 on: September 30, 2019, 08:15:48 pm »


Try this to create and paste color constants straight into your code:
Code: QB64: [Select]
  1. _TITLE "Color CONST for _RGBA32(red, green, blue, alpha)" 'B+ 2019-05-19
  2. '2019-05-26 update this for mouse inputs
  3. '>>>>>>>>>>>> test your colors here
  4. '>>>>>>>>>>>> then create and name Hex string CONSTs if you want to the Clipboard
  5.  
  6. 'sample clipping
  7. CONST Purple = &HFFB400B4
  8. CONST Red = &HFFFA3232
  9.  
  10. SCREEN _NEWIMAGE(800, 600, 32)
  11.     INPUT "Clear clipboard? enter y for yes "; w$
  12.     IF w$ = "y" THEN _CLIPBOARD$ = ""
  13. r = 128: g = 128: b = 128: a = 128
  14. COLOR &HFFDDDDDD, 0
  15.     CLS
  16.     MakeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  17.     slider 16, 10, r, "Red"
  18.     slider 16, 60, g, "Green"
  19.     slider 16, 110, b, "Blue"
  20.     slider 16, 160, a, "Alpha"
  21.     _PRINTSTRING (250, 260), "Press c to create CONST for Clipboard"
  22.     _PRINTSTRING (210, 280), "Use this Hex string for color CONST: " + MakeConst$
  23.     LINE (90, 300)-(710, 590), , B
  24.     LINE (100, 310)-(700, 580), VAL(MakeConst$), BF
  25.  
  26.     mb = _MOUSEBUTTON(1)
  27.     IF mb THEN 'clear it
  28.         mx = _MOUSEX: my = _MOUSEY
  29.         IF mx >= 16 AND mx <= 784 THEN
  30.             IF my >= 10 AND my <= 50 THEN
  31.                 r = _ROUND((mx - 16) / 3)
  32.             ELSEIF my >= 60 AND my <= 100 THEN
  33.                 g = _ROUND((mx - 16) / 3)
  34.             ELSEIF my >= 110 AND my <= 150 THEN
  35.                 b = _ROUND((mx - 16) / 3)
  36.             ELSEIF my >= 160 AND my <= 200 THEN
  37.                 a = _ROUND((mx - 16) / 3)
  38.             END IF
  39.         END IF
  40.     END IF
  41.     k$ = INKEY$
  42.     IF k$ = "q" THEN EXIT DO
  43.     IF k$ = "c" THEN
  44.         LOCATE 16, 30
  45.         INPUT "Enter name for your color CONST "; cname$
  46.         _CLIPBOARD$ = _CLIPBOARD$ + CHR$(10) + "CONST " + cname$ + " = " + MakeConst$
  47.     END IF
  48.     _DISPLAY
  49.     _LIMIT 60
  50.  
  51. SUB slider (x, y, value, label$)
  52.     SELECT CASE label$
  53.         CASE "Red": c~& = &HFFFF0000
  54.         CASE "Green": c~& = &HFF008800
  55.         CASE "Blue": c~& = &HFF0000FF
  56.         CASE "Alpha": c~& = &H88FFFFFF
  57.     END SELECT
  58.     LINE (x, y)-STEP(768, 40), c~&, B
  59.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  60.     s$ = label$ + " = " + _TRIM$(STR$(value))
  61.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  62.  

  [ You are not allowed to view this attachment ]

Fresh from my Clipboard:
CONST White = &HFFFAFAFA
« Last Edit: September 30, 2019, 08:18:00 pm by bplus »

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Please STOP kidding me with CONST!
« Reply #3 on: September 30, 2019, 11:51:11 pm »
It wasn’t very long ago when a CONST couldn’t even process another CONST at all.  (I think v1.2 or v1.3 is when the functionality was added.) 

what do you mean "process another CONST"? as I have always been able to CONST TRUE = -1, FALSE = NOT TRUE
isn't FALSE = NOT TRUE processing the constant TRUE? I must be misinterpreting something.
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Please STOP kidding me with CONST!
« Reply #4 on: September 30, 2019, 11:59:25 pm »
what do you mean "process another CONST"? as I have always been able to CONST TRUE = -1, FALSE = NOT TRUE
isn't FALSE = NOT TRUE processing the constant TRUE? I must be misinterpreting something.

Clarification: Not with any of the functions that called the internal math routine.

CONST X = 180
CONST SinX = SIN(X) <—— ERRORED OUT AND DID NOT WORK.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Please STOP kidding me with CONST!
« Reply #5 on: October 01, 2019, 12:49:40 am »
AH, got it now.
Granted after becoming radioactive I only have a half-life!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Please STOP kidding me with CONST!
« Reply #6 on: October 01, 2019, 06:02:09 pm »
Hi Bplus
sorry I have forgotten the utility that you have built some time ago

thank to remind it to me I'll use to get HEX value so it seems I'm a good expert programmer :-)
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Please STOP kidding me with CONST!
« Reply #7 on: October 01, 2019, 06:12:53 pm »
Hi Steve

Quote
Here’s what you need to do to fix the issue:

1) Relax.  Repeat, repeatedly, “Nobody is out to get me, or sabotage my efforts coding with CONST and colors.”  Breath long, deep breaths.  Inhale.  Exhale.  Repeat, repeatedly, “Nobody is out to get me, or sabotage my efforts coding with CONST and colors.”   Then...
2) Work around the issue by placing literal values in the function.
3) OR, learn to write color values as their hex equivalent.
4) OR, go into QB64.bas, scroll down to the label “stevewashere:”, and just a short ways after that — past the $PRECOMPILER commands — you’ll see “CONST” and the two _RGB and _RGBA areas.  Correct the issue yourself and share the results with us.
5) OR, simply post a bug report and wait until somebody decides to look into the issue and add the functionality there.

Either that, or take Pete’s recommended method:
6) Just code in SCREEN 0, where you don’t need no complicated CONST for colors.

thanks,
1. already done!

2. already done, but it seems to me go back and not forward in programming!

3. It seems a good way to workaround the compiler status quo (using Bplus' tool it is easy and fast!)

4. I have taken now a look and I have found also "stevewashere2:" but some name of variables seems to be the cousins of that used in the esoteric Larryln's interpreter...https://www.qb64.org/forum/index.php?topic=1754.msg109983#msg109983. I must imagine how this parser goes working... after all things, also you at beginning have had to dig into code to understand the structure of the program.

5. in the past done, but now I post only if the issue can be interesting for someother user of QB64

6. it is the last option... I come out from ASCII world that I find fantastic...but we know more limited for output to the screen!

Thanks for you help and your tips!
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Please STOP kidding me with CONST!
« Reply #8 on: October 01, 2019, 06:43:11 pm »
Wait,...   Stevewashere2:

;-))