Author Topic: Create Color CONSTs for Clipboard  (Read 3971 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Create Color CONSTs for Clipboard
« on: May 19, 2019, 11:27:57 am »
Code: QB64: [Select]
  1. _TITLE "Color CONST for _RGBA32(red, green, blue, alpha)" 'B+ 2019-05-19
  2.  
  3. '>>>>>>>>>>>> test your colors here
  4. '>>>>>>>>>>>> then create and name Hex string CONSTs if you want to the Clipboard
  5.  
  6. SCREEN _NEWIMAGE(800, 600, 32)
  7.     INPUT "Clear clipboard? enter y for yes "; w$
  8.     IF w$ = "y" THEN _CLIPBOARD$ = ""
  9.     CLS
  10.     PRINT "Enter 4 numbers (0-255) for _RGBA32( red, green, blue, alpha)  you want to test "
  11.     INPUT "(Don't forget commas) "; r, g, b, a
  12.     MakeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  13.     LINE (90, 300)-(710, 590), , B
  14.     LINE (100, 310)-(700, 580), VAL(MakeConst$), BF
  15.     PRINT "Use this Hex string for color CONST: "; MakeConst$
  16.     INPUT "  Press c enter to add to ClipBoard, press q enter to quit, just enter to continue.."; w$
  17.     IF w$ = "c" THEN
  18.         INPUT "Name your CONST "; cname$
  19.         _CLIPBOARD$ = _CLIPBOARD$ + CHR$(10) + "CONST " + cname$ + " = " + MakeConst$
  20.     END IF
  21.     IF w$ = "q" THEN SYSTEM
  22.  
  23. 'sample from clipboard
  24. CONST rarelyRed = &H00FF0000
  25. CONST barelyBlue = &H0A0000FF
  26.  
  27.  

Marked as best answer by bplus on June 19, 2019, 09:05:01 am

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Create Color CONSTs for Clipboard
« Reply #1 on: May 26, 2019, 10:08:28 pm »
Hi TempodiBasic :)

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. SCREEN _NEWIMAGE(800, 600, 32)
  7.     INPUT "Clear clipboard? enter y for yes "; w$
  8.     IF w$ = "y" THEN _CLIPBOARD$ = ""
  9. r = 128: g = 128: b = 128: a = 128
  10. COLOR &HFFDDDDDD, 0
  11.     CLS
  12.     MakeConst$ = "&H" + RIGHT$(STRING$(8, "0") + HEX$(_RGBA32(r, g, b, a)), 8)
  13.     slider 16, 10, r, "Red"
  14.     slider 16, 60, g, "Green"
  15.     slider 16, 110, b, "Blue"
  16.     slider 16, 160, a, "Alpha"
  17.     _PRINTSTRING (250, 260), "Press c to create CONST for Clipboard"
  18.     _PRINTSTRING (210, 280), "Use this Hex string for color CONST: " + MakeConst$
  19.     LINE (90, 300)-(710, 590), , B
  20.     LINE (100, 310)-(700, 580), VAL(MakeConst$), BF
  21.  
  22.     mb = _MOUSEBUTTON(1)
  23.     IF mb THEN 'clear it
  24.         mx = _MOUSEX: my = _MOUSEY
  25.         IF mx >= 16 AND mx <= 784 THEN
  26.             IF my >= 10 AND my <= 50 THEN
  27.                 r = _ROUND((mx - 16) / 3)
  28.             ELSEIF my >= 60 AND my <= 100 THEN
  29.                 g = _ROUND((mx - 16) / 3)
  30.             ELSEIF my >= 110 AND my <= 150 THEN
  31.                 b = _ROUND((mx - 16) / 3)
  32.             ELSEIF my >= 160 AND my <= 200 THEN
  33.                 a = _ROUND((mx - 16) / 3)
  34.             END IF
  35.         END IF
  36.     END IF
  37.     k$ = INKEY$
  38.     IF k$ = "q" THEN EXIT DO
  39.     IF k$ = "c" THEN
  40.         LOCATE 16, 30
  41.         INPUT "Enter name for your color CONST "; cname$
  42.         _CLIPBOARD$ = _CLIPBOARD$ + CHR$(10) + "CONST " + cname$ + " = " + MakeConst$
  43.     END IF
  44.     _DISPLAY
  45.     _LIMIT 60
  46.  
  47. SUB slider (x, y, value, label$)
  48.     SELECT CASE label$
  49.         CASE "Red": c~& = &HFFFF0000
  50.         CASE "Green": c~& = &HFF008800
  51.         CASE "Blue": c~& = &HFF0000FF
  52.         CASE "Alpha": c~& = &H88FFFFFF
  53.     END SELECT
  54.     LINE (x, y)-STEP(768, 40), c~&, B
  55.     LINE (x, y)-STEP(3 * value, 40), c~&, BF
  56.     s$ = label$ + " = " + _TRIM$(STR$(value))
  57.     _PRINTSTRING (x + 384 - 4 * LEN(s$), y + 12), s$
  58.  
EDIT: add _ROUND
« Last Edit: May 26, 2019, 10:17:20 pm by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Create Color CONSTs for Clipboard
« Reply #2 on: May 30, 2019, 09:58:26 am »
Hi Bplus
thank you very much for your attention and activity
I find very handful and useful both OldDosversion and MouseGraphicVersion
 
_RGBA32Tool Bplus.jpg
Programming isn't difficult, only it's  consuming time and coffee