Ooops
November 25, 2020, 05:19:37 AM

Author Topic: [bb] Colors by name by Fernhout [ 1+ years ago ]  (Read 662 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Colors by name by Fernhout [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Colors
Author : name by Fernhout
Posted : 1+ years ago

Description : I have always the problem if i want to use a special color, i don't know the R,G,B combination. So for this use i have starte a DATA array so i only have to remember the name of the color. Pass the name of the color to this function and the color is set.  For those who have more color natations please insert them in the file or giver them to me so i can expand this file. The color name provided in the string is NOT case sensetive

Code :
Code: BlitzBasic
  1. ; Include file for making color by using the names insted of using RGB value
  2. ; Intial colors are in now.
  3. ; --------------------------------------------------------------
  4. ; Put this part in front of the program. It wil execute one time to read in al the data.
  5. ; KEEP IN MIND that this part may not to place in any kind of loop.
  6. ;---------------------------------------------------------------
  7. Dim Colors$(500)        ; Text colors
  8. Dim NumColors(500,2)    ; The numbers
  9. Global TotalColors = 18  ;<---- This number is the total of named colors. Ajust it to your needs.
  10. Restore ColorList
  11. For x = 0 To Totalcolors
  12.         Read Colors$(x)
  13.         Read NumColors(x,0)
  14.         Read NumColors(x,1)
  15.         Read NumColors(x,2)
  16. Next
  17.  
  18. ;--------------------------------------------------------
  19. ; Function SetColor
  20. ; Give a color name in string. Unknown color name result in White color
  21. ;--------------------------------------------------------
  22. Function SetColor (ColorName$)
  23.         ColorNames$ = Upper$ (ColorNames$)
  24.         Color 255,255,255 ; Pre define color if not found the name then standard white returns
  25.         For x = 0 To TotalColors
  26.                 If Upper$ (ColorName$) = Upper$(Colors$(x))
  27.                         Color NumColors(x,0),NumColors(x,1),NumColors(x,2)
  28.                 End If
  29.         Next
  30. End Function
  31.  
  32.  
  33. ;-----------------------------------------------------------
  34. ; For now its a short list but in the future its expand.
  35. ; You input is also important.
  36. ; If you add colors please repost it back to BB.
  37. ;-----------------------------------------------------------
  38. .ColorList
  39. ; Standard color list (7)
  40. Data "White",255,255,255
  41. Data "Red",255,0,0
  42. Data "Green",0,255,0
  43. Data "Blue",0,0,255
  44. Data "Black",0,0,0
  45. Data "Cyan",0,255,255
  46. Data "Magenta",255,0,255
  47.  
  48. ; Half way colors
  49. Data "Gray",125,125,125
  50. ; Most used colors name (11)
  51. Data "Silver",176,176,176
  52. Data "Dark_grey",100,100,100
  53. Data "Pale_green",152,251,152
  54. Data "Light_sky_blue",135,206,250
  55. Data "Orange",255,165,0
  56. Data "Brown",200,150,100
  57. Data "Pale_pink",255,200,200
  58. Data "Light_grey",170,170,170
  59. Data "Mid_red",255,63,63
  60. Data "Light_red",255,127,127
  61. Data "Pink",255,191,191


Comments :


Rob Farley(Posted 1+ years ago)

 A slightly different approach and maybe a touch faster may be:Assuming this formula
Code: [Select]
r=255
g=128
b=0
c=(r*65536)+(g*256)+b
Color 0,0,c
Text 0,0,"*** " + c + " ***"
WaitKey
This means you can create a bunch of constants like
Code: [Select]
Const col_White = (255*65536)+(255*256)+255
Const col_Yellow = (255*65536)+(255*256)+0
Const col_Blue = (0*65536)+(0*256)+255
Const col_Orange = (255*65536)+(128*256)+0
etc etc etc
Then just use them like:
Code: [Select]
Color 0,0,col_yellow
Text 0,10,"Yellow"
WaitKey
I would suggest just creating a dirty big include that you stick at the top of your program so you don't need to see all the constants.


CS_TBL(Posted 1+ years ago)

 Or you could make a single function, without globals, which has all colors defined in it. The only function-arguement would be a string. Next you make a semi-intelligent parser so you can input:"Red dark""rEd DArK""dark        red""        dARK   Red    "etc. all being the same color, so the whole function would be a bit foolproof.Less globals = more power .. you never know whether a global was already in use in some new set o' functions you're going to include. Heck,  imagine 2 different color-alias-systems!*sigh*, ideas ideas ...


Fernhout(Posted 1+ years ago)

 Thanks for the reaction CS_TBL.I was indeed thinking make a function and include it later if you need it.I see Yelloy is not in. so here the line for yellowData "Yellow",255,255,0Add it and adjust 18 to 19I did also make the thinking rule if i use a color name i don't want to think about the way i have to write it. So i make it case unsencetive. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal