March 05, 2021, 07:14:47 AM

Author Topic: [bb] Quick Color Function by -Rick- [ 1+ years ago ]  (Read 695 times)

Offline BlitzBot

[bb] Quick Color Function by -Rick- [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Quick Color Function
Author : -Rick-
Posted : 1+ years ago

Description : A convenience function to call basic colors by name as well
 as set 5 special effects for making whatever is colored
 have various effects. Color call can use text word such as
"blk", "black" or just a 0. Keys 1,2,3,4 and 0 set the effect

The effects are :
0 - Solid Color
1 - Blink Color On and Off
2 - Pulse Color Dark to Bright
3 - Color Brightens then resets Black
4 - Color Darkens then resets Bright

Usage:

SetCol (color, Effect)


Code :
Code: BlitzBasic
  1. Graphics 800,600,16,2
  2.  
  3.  Global key$ = "0"
  4.  
  5.  While Not KeyHit(1)
  6.         SetCol("yellow",key)
  7.         Text GraphicsWidth()/2,GraphicsHeight()/2,"This is a test",1,1
  8.         If KeyHit(2) Then key = "1"
  9.         If KeyHit(3) Then key = "2"
  10.         If KeyHit(4) Then key = "3"
  11.         If KeyHit(5) Then key = "4"
  12.         If KeyHit(11) Then key = "0"
  13.  Wend
  14.  End
  15.  
  16.  
  17. ;XXXXXXXXXXXXXXXXXXXXXX
  18. ;       SET COLOR
  19. ;XXXXXXXXXXXXXXXXXXXXXX
  20. Function SetCol(Kolor$="white",Effect$ = "0")
  21.  
  22.         FTime$ = Str(MilliSecs())
  23.         Time$ = Mid(Ftime,Len(ftime)-2,2)
  24.         Fade# = Float(Time) * .01
  25.         Effect$ = Lower(Effect)
  26.  
  27.         Select Effect
  28.                 Case 0,"none"
  29.                         fade = 1.0
  30.                 Case 1,"blink"
  31.                         If fade < .5 Then
  32.                                 fade = 1
  33.                         Else
  34.                                 fade = 0
  35.                         EndIf
  36.                 Case 2,"pulse"
  37.                         If Fade < .5 Then
  38.                                 Fade# = 1 - Fade
  39.                         EndIf
  40.                 Case 3,"charge"
  41.                         If fade < 1 Then
  42.                                 fade = fade + fade / 5
  43.                         Else
  44.                                 fade = 0
  45.                         EndIf
  46.                 Case 4,"fade"
  47.                         If fade > 0 Then
  48.                                 fade = 1 - fade
  49.                         Else
  50.                                 fade = 1
  51.                         EndIf
  52.         End Select
  53.  
  54.         Kolor = Lower(Kolor)
  55.         Select Kolor
  56.                 Case "0","blk","black"                                                  ;Black
  57.                         Color 0,0,0
  58.                 Case "1","red"                                                                  ;Red
  59.                         Color 255*Fade,0,0     
  60.                 Case "2","grn","green"                                                  ;Green
  61.                         Color 0,255*Fade,0
  62.                 Case "3","blu","blue"                                                   ;Blue
  63.                         Color 0,0,255*Fade
  64.                 Case "4","yel","yellow"                                                 ;Yellow
  65.                         Color 255*Fade,255*Fade,0
  66.                 Case "5","drd","dred","darkred"                                 ;Dark Red
  67.                         Color 150*Fade,0,0
  68.                 Case "6","dgr","dgreen","darkgreen"                             ;Dark Green
  69.                         Color 0,150*Fade,0
  70.                 Case "7","dbl","dblue","darkblue"                               ;Dark Blue
  71.                         Color 0,0,150*Fade
  72.                 Case "8","dyl","dyellow","darkyellow"                   ;Dark Yellow
  73.                         Color 150*Fade,150*Fade,0
  74.                 Case "9","pur","purple"                                                 ;Purple
  75.                         Color 255*Fade,0,255*Fade
  76.                 Case "10","whi","white"                                                 ;White
  77.                         Color 255*Fade,255*Fade,255*Fade
  78.                 Case "11","gry","grey","gray"                                   ;Grey
  79.                         Color 150*Fade,150*Fade,150*Fade
  80.                 Case "12","tel","teal"                                                  ;Teal
  81.                         Color 0,255*Fade,255*Fade
  82.                 Case "13","dgry","dgrey","dark grey","dark gray";Dark Grey
  83.                         Color 50*fade,50*Fade,50*Fade  
  84.         End Select
  85. End Function


Comments :


virtlands(Posted 1+ years ago)

 Congrats. I've always enjoyed the concept of joining color and code together.  If you'd like to take it a step further, you can include names for thousands of colors (instead of just 13).{ In the case of involving 1000s of colors, I don't think you'd be using a CASE statement.  There's got to be a better way. }There are various websites that offer large lists of color names. I'm sure they'd let you copy these color names for your own code. Best to include a "Copied this from this ..." tribute to be nice.Lists of Colors:Wikipedia: <a href="http://tinyurl.com/ak6h49h" target="_blank">http://tinyurl.com/ak6h49h[/url]  {<-- List of colors, A-M}<a href="http://tinyurl.com/ccmheyy" target="_blank">http://tinyurl.com/ccmheyy[/url]  {<-- List of colors, N-Z}Color Names Supported by All Browsers:<a href="http://www.w3schools.com/html/html_colornames.asp" target="_blank">http://www.w3schools.com/html/html_colornames.asp[/url]ColorHexa List of Colors:  { also contains color computer for HEX,RGB, CMYK, HSL, HSV, web-safe }<a href="http://www.colorhexa.com/color-names" target="_blank">http://www.colorhexa.com/color-names[/url]Cloford, 500+ named colors:<a href="http://cloford.com/resources/colours/500col.htm" target="_blank">http://cloford.com/resources/colours/500col.htm[/url]WorkWithColor:<a href="http://www.workwithcolor.com/color-names-01.htm" target="_blank">http://www.workwithcolor.com/color-names-01.htm[/url]Color Schemer is a website that offers color harmony and combinations.<a href="http://www.colorschemer.com/blog/2007/07/24/140-named-colors/" target="_blank">http://www.colorschemer.com/blog/2007/07/24/140-named-colors/[/url]Name that Color: {This website lets you input color codes, and it will do its best to name that color.}<a href="http://chir.ag/projects/name-that-color/#BE798E" target="_blank">http://chir.ag/projects/name-that-color/#BE798E[/url]{ This also lets you find names of colors: }<a href="http://www.colblindor.com/color-name-hue/" target="_blank">http://www.colblindor.com/color-name-hue/[/url]Huge Google Search of Color Names: <a href="http://tinyurl.com/co9g7ay" target="_blank">http://tinyurl.com/co9g7ay[/url]Huge Google Search of Color Charts: <a href="http://tinyurl.com/bnwtb8t" target="_blank">http://tinyurl.com/bnwtb8t[/url]Maybe you can just invent a program that absorbs color data directly from the html, (customized for each webpage, of course) to save your fingers from all the typing and also on your patience.An .html is similar to a .txt file, therefore it is possible to read it in Blitz3D.(Next is just an interesting color sampling display I found.)<a href="http://upload.wikimedia.org/wikipedia/commons/2/2b/SVG_Recognized_color_keyword_names.svg" target="_blank">http://upload.wikimedia.org/wikipedia/commons/2/2b/SVG_Recognized_color_keyword_names.svg[/url]


-Rick-(Posted 1+ years ago)

 This is just intended for a quick color function with very minor effects that I can cut and paste into various programs that have a basic color scheme. Mostly for quick text color changes or simple graphics rectangles/ovals. I can never seem to recall the correct color codes for various colors so use this to save a little time while programming and thought it might be helpful for newer programmers.


*(Posted 1+ years ago)

 couldnt you use 'Select Upper( Kolor )' then just check for uppercase versions of the colours as I could put bLack and it would break the code as it is now :)


-Rick-(Posted 1+ years ago)

 Great idea on the use of upper/lower EdzUp. I went with lower since all Caps always annoy me :P. Added in a few other simple effects and cleaned up the Kolor Select code. Also made it as a stand alone to quickly test the effects and people can just strip out the function itself for use.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal