Author Topic: Simple colours routine  (Read 4833 times)

0 Members and 1 Guest are viewing this topic.

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Simple colours routine
« on: March 01, 2019, 07:40:36 am »
I started, many years ago, with GWbasic and then with QB45.
Between the end of the 80s and the beginning of the 90s I had fun programming videogames for my friends.
Then, I left the basic.
A few months ago I found QB64 and thank you for making me go back in years.
I enclose a small routine, which I use to remind me of the numbering of the first 256 colors.
It is not optimized, because I use it only for myself.
Sorry for any errors in English, but my level is just sufficient.
We stay in touch !

------------------------------
handle& = _NEWIMAGE(1000, 600, 256)
SCREEN handle&

CLR = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY)-(WLX + 30, WLY + 30), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 40)-(WLX + 30, WLY + 70), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 80)-(WLX + 30, WLY + 110), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 120)-(WLX + 30, WLY + 150), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 160)-(WLX + 30, WLY + 190), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 200)-(WLX + 30, WLY + 230), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 240)-(WLX + 30, WLY + 270), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 280)-(WLX + 30, WLY + 310), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 320)-(WLX + 30, WLY + 350), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX

WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 360)-(WLX + 30, WLY + 390), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX
WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 400)-(WLX + 30, WLY + 430), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX
WLX = 0

FOR BOX = 1 TO 25
    LINE (WLX, WLY + 440)-(WLX + 30, WLY + 470), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX
WLX = 0

FOR BOX = 1 TO 10
    LINE (WLX, WLY + 480)-(WLX + 30, WLY + 510), CLR, BF
    CLR = CLR + 1
    WLX = WLX + 34
NEXT BOX


JH:
WLX = 2: WLY = 0
LOCATE 34, 3: INPUT A
'LINE (WLX + (A + 4), WLY + 22)-(WLX + (A + 6), WLY + 27), 14, B

LINE (270, 150)-(370, 250), A, BF

LINE (0, 300)-(30, 330), A + 1, BF
LINE (40, 300)-(70, 330), A + 2, BF
LINE (80, 300)-(110, 330), A + 3, BF
LINE (120, 300)-(150, 330), A + 4, BF
LINE (160, 300)-(190, 330), A + 5, BF
LINE (200, 300)-(230, 330), A + 6, BF
LINE (240, 300)-(270, 330), A + 7, BF
LINE (280, 300)-(310, 330), A + 8, BF



GOTO JH

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Simple colours routine
« Reply #1 on: March 01, 2019, 09:07:42 am »
Welcome to forum qb4ever!

Your history a bit like mine, except I never worked with 256 color scheme that I recall. I was quite taken by RGB and RGBA color scheme!

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Simple colours routine
« Reply #2 on: March 01, 2019, 09:24:07 am »
Welcome to forum qb4ever!

Your history a bit like mine, except I never worked with 256 color scheme that I recall. I was quite taken by RGB and RGBA color scheme!

:) I remember SCREEN 13......

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Simple colours routine
« Reply #3 on: March 01, 2019, 10:25:31 am »
Here is my RGB color picker / helper from 4 years ago when I started back with another Basic, translated to QB64:
Code: QB64: [Select]
  1. _TITLE "RGB Color Values and Chart:   key e | r changes red, f | g changes green, v | b changes blue "
  2. 'B+ 2019-03-01 translated from
  3. 'color chart.bas SmallBASIC modified 2015-04-27
  4. '2015-04-28 a work in progress MGA/B+
  5.  
  6. CONST xmax = 700
  7. CONST ymax = 620
  8. DIM c AS _UNSIGNED LONG 'type for color variables
  9. SCREEN _NEWIMAGE(xmax, ymax, 32)
  10. _SCREENMOVE 300, 100
  11.  
  12. r = 125: g = 125: b = 125
  13. rect 0, 0, 512, 80, _DEFAULTCOLOR
  14. frect 10, 10, 502, 70, _RGB32(r, g, b)
  15. COLOR _RGB32(255, 0, 0): LOCATE 7, 7: PRINT "e-/r+ for red  "
  16. COLOR _RGB32(0, 255, 0): LOCATE 7, 27: PRINT "f-/g+ for green"
  17. COLOR _RGB32(0, 0, 255): LOCATE 7, 47: PRINT "v-/+b for blue"
  18. COLOR _RGB32(255, 255, 255): LOCATE 9, 2: PRINT " 0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15   col*16+15 = c"
  19. LOCATE 11, 67: PRINT "_rgb32(c,c,c)"
  20. LOCATE 13, 67: PRINT "_rgb32(c,0,0)"
  21. LOCATE 15, 67: PRINT "_rgb32(0,c,0)"
  22. LOCATE 17, 67: PRINT "_rgb32(0,0,c)"
  23. LOCATE 19, 67: PRINT "_rgb32(c,c,0)"
  24. LOCATE 21, 67: PRINT "_rgb32(c,0,c)"
  25. LOCATE 23, 67: PRINT "_rgb32(0,c,c)"
  26. LOCATE 25, 67: PRINT "_rgb32(255,c,0)"
  27. LOCATE 27, 67: PRINT "_rgb32(255,0,c)"
  28. LOCATE 29, 67: PRINT "_rgb32(c,255,0)"
  29. LOCATE 31, 67: PRINT "_rgb32(0,255,c)"
  30. LOCATE 33, 67: PRINT "_rgb32(c,0,255)"
  31. LOCATE 35, 67: PRINT "_rgb32(0,c,255)"
  32.  
  33. sqx = 32: sqy = 32: yoff = 173
  34. FOR i = 0 TO 207
  35.     row = INT(i / 16): col = i MOD 16
  36.     cx = sqx * col: cy = sqy * row + yoff
  37.     c = col * 16 + 15
  38.     IF i > -1 AND i < 16 THEN c = _RGB32(c, c, c)
  39.     IF i > 15 AND i < 32 THEN c = _RGB32(c, 0, 0)
  40.     IF i > 31 AND i < 48 THEN c = _RGB32(0, c, 0)
  41.     IF i > 47 AND i < 64 THEN c = _RGB32(0, 0, c)
  42.     IF i > 63 AND i < 80 THEN c = _RGB32(c, c, 0)
  43.     IF i > 79 AND i < 96 THEN c = _RGB32(c, 0, c)
  44.     IF i > 95 AND i < 112 THEN c = _RGB32(0, c, c)
  45.     IF i > 111 AND i < 128 THEN c = _RGB32(255, c, 0)
  46.     IF i > 127 AND i < 144 THEN c = _RGB32(255, 0, c)
  47.     IF i > 143 AND i < 160 THEN c = _RGB32(c, 255, 0)
  48.     IF i > 159 AND i < 176 THEN c = _RGB32(0, 255, c)
  49.     IF i > 175 AND i < 192 THEN c = _RGB32(c, 0, 255)
  50.     IF i > 191 AND i < 208 THEN c = _RGB32(0, c, 255)
  51.     frect cx + 8, cy - 20, cx + 8 + sqx - 1, cy - 20 + sqy - 1, c
  52. k$ = " "
  53. WHILE ASC(k$) <> 27
  54.     COLOR _RGB32(255, 0, 0): LOCATE 7, 12: PRINT "    "
  55.     LOCATE 7, 12: PRINT r
  56.     COLOR _RGB32(0, 255, 0): LOCATE 7, 32: PRINT "    "
  57.     LOCATE 7, 32: PRINT g
  58.     COLOR _RGB32(0, 0, 255): LOCATE 7, 52: PRINT "    "
  59.     LOCATE 7, 52: PRINT b
  60.     COLOR _RGB32(255, 255, 255)
  61.     rect 0, 0, 512, 80, _DEFAULTCOLOR
  62.     frect 10, 10, 502, 70, _RGB32(r, g, b)
  63.     k$ = INKEY$
  64.     WHILE LEN(k$) = 0
  65.         k$ = INKEY$
  66.     WEND
  67.     IF k$ = "e" THEN r = r - 5: IF r < 0 THEN r = 0
  68.     IF k$ = "r" THEN r = r + 5: IF r > 255 THEN r = 255
  69.     IF k$ = "f" THEN g = g - 5: IF g < 0 THEN g = 0
  70.     IF k$ = "g" THEN g = g + 5: IF g > 255 THEN g = 255
  71.     IF k$ = "v" THEN b = b - 5: IF b < 0 THEN b = 0
  72.     IF k$ = "b" THEN b = b + 5: IF b > 255 THEN b = 255
  73.     _DISPLAY 'stop flickering
  74.     _LIMIT 30 'save cpu fan
  75.  
  76. SUB rect (x1, y1, x2, y2, c AS _UNSIGNED LONG)
  77.     LINE (x1, y1)-(x2, y2), c, B
  78. SUB frect (x1, y1, x2, y2, c AS _UNSIGNED LONG)
  79.     LINE (x1, y1)-(x2, y2), c, BF
  80.  
  81.  
« Last Edit: March 01, 2019, 10:27:03 am by bplus »

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Simple colours routine
« Reply #4 on: March 01, 2019, 11:52:42 am »
Thanks bplus

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Simple colours routine
« Reply #5 on: March 01, 2019, 12:56:55 pm »
You should only program in SCREEN 0, the only screen any real programmer needs!

Viva Italia, and your English is great. I't probably better than mine, and I'm third generation Italian from my father's side. I don't speak Italian, except a few swear words... from my mother's side. I hope the humor isn't lost in any translation. Kidding about screens, too.

Welcome to the forum. I'm an old BASIC programmer, too. Started with Texas Instrument TIBasic in 1980. I hope you stay and get a chance to meet TempodiBasic: https://www.qb64.org/forum/index.php?action=profile;u=27 He's from Italy, too.

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

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Simple colours routine
« Reply #6 on: March 01, 2019, 01:41:37 pm »
Great Pete !
So I'm not the oldest programmer : )

FellippeHeitor

  • Guest
Re: Simple colours routine
« Reply #7 on: March 01, 2019, 02:24:01 pm »
Welcome to the forum qb4ever!

Here's a simplification of your code, if you allow me. If you don't like the numbers showing, just set showNumbers = 0.

When you post code, make sure to enclose your source in a [code] block:

[code]
Code: QB64: [Select]
  1. CONST showNumbers = 1
  2.  
  3. handle& = _NEWIMAGE(1000, 600, 256)
  4. SCREEN handle&
  5. FOR BOX = 1 TO 25
  6.     WLX = 0
  7.     FOR CLR = CLR TO CLR + 24
  8.         IF CLR > 309 THEN EXIT FOR
  9.         LINE (WLX, WLY)-(WLX + 30, WLY + 30), CLR, BF
  10.  
  11.         IF showNumbers THEN
  12.             COLOR 0
  13.             _PRINTSTRING (WLX + 1, WLY + 1), LTRIM$(STR$(CLR))
  14.             COLOR 15
  15.             _PRINTSTRING (WLX, WLY), LTRIM$(STR$(CLR))
  16.         END IF
  17.  
  18.         WLX = WLX + 34
  19.     NEXT
  20.     WLY = WLY + 40
  21. NEXT BOX
  22.  
  23.     LOCATE 34, 3: INPUT A
  24.  
  25.     LINE (270, 150)-(370, 250), A, BF
  26.  
  27.     LINE (0, 300)-(30, 330), A + 1, BF
  28.     LINE (40, 300)-(70, 330), A + 2, BF
  29.     LINE (80, 300)-(110, 330), A + 3, BF
  30.     LINE (120, 300)-(150, 330), A + 4, BF
  31.     LINE (160, 300)-(190, 330), A + 5, BF
  32.     LINE (200, 300)-(230, 330), A + 6, BF
  33.     LINE (240, 300)-(270, 330), A + 7, BF
  34.     LINE (280, 300)-(310, 330), A + 8, BF
[/code]

Offline qb4ever

  • Newbie
  • Posts: 40
  • LOCATE 15,15: COLOR 14: PRINT "Hello World!"
    • View Profile
Re: Simple colours routine
« Reply #8 on: March 01, 2019, 03:15:07 pm »
Welcome to the forum qb4ever!

Here's a simplification of your code, if you allow me. If you don't like the numbers showing, just set showNumbers = 0.

When you post code, make sure to enclose your source in a [code] block:

[code]
Code: QB64: [Select]
  1. CONST showNumbers = 1
  2.  
  3. handle& = _NEWIMAGE(1000, 600, 256)
  4. SCREEN handle&
  5. FOR BOX = 1 TO 25
  6.     WLX = 0
  7.     FOR CLR = CLR TO CLR + 24
  8.         IF CLR > 309 THEN EXIT FOR
  9.         LINE (WLX, WLY)-(WLX + 30, WLY + 30), CLR, BF
  10.  
  11.         IF showNumbers THEN
  12.             COLOR 0
  13.             _PRINTSTRING (WLX + 1, WLY + 1), LTRIM$(STR$(CLR))
  14.             COLOR 15
  15.             _PRINTSTRING (WLX, WLY), LTRIM$(STR$(CLR))
  16.         END IF
  17.  
  18.         WLX = WLX + 34
  19.     NEXT
  20.     WLY = WLY + 40
  21. NEXT BOX
  22.  
  23.     LOCATE 34, 3: INPUT A
  24.  
  25.     LINE (270, 150)-(370, 250), A, BF
  26.  
  27.     LINE (0, 300)-(30, 330), A + 1, BF
  28.     LINE (40, 300)-(70, 330), A + 2, BF
  29.     LINE (80, 300)-(110, 330), A + 3, BF
  30.     LINE (120, 300)-(150, 330), A + 4, BF
  31.     LINE (160, 300)-(190, 330), A + 5, BF
  32.     LINE (200, 300)-(230, 330), A + 6, BF
  33.     LINE (240, 300)-(270, 330), A + 7, BF
  34.     LINE (280, 300)-(310, 330), A + 8, BF
[/code]

Thanks Felipe, and sorry for don't post the source in a code block.

I went back to using BASIC three months ago after 22 years that I did not write a line of software:).

I have to recover from my long hibernation ....

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Simple colours routine
« Reply #9 on: March 01, 2019, 08:18:30 pm »
Who the hell you calling old??!! Nuts, I left my remote mouse in the frig again.

After the LOCATE 34. 3: INPUT A

You might want to add in...

LOCATE 34, 5: PRINT SPACE$(60);

That will erase the previous input, after the Enter key is pressed.

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