Code archives/Graphics/Quick Color Function

This code has been declared by its author to be Public Domain code.

Download source code

Quick Color Function by -Rick-2013
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)
Graphics 800,600,16,2
 
 Global key$ = "0"
 
 While Not KeyHit(1)
 	SetCol("yellow",key)
 	Text GraphicsWidth()/2,GraphicsHeight()/2,"This is a test",1,1
 	If KeyHit(2) Then key = "1"
 	If KeyHit(3) Then key = "2"
 	If KeyHit(4) Then key = "3"
 	If KeyHit(5) Then key = "4"
 	If KeyHit(11) Then key = "0"
 Wend
 End


;XXXXXXXXXXXXXXXXXXXXXX
;	SET COLOR
;XXXXXXXXXXXXXXXXXXXXXX
Function SetCol(Kolor$="white",Effect$ = "0")

	FTime$ = Str(MilliSecs())
	Time$ = Mid(Ftime,Len(ftime)-2,2)
	Fade# = Float(Time) * .01
	Effect$ = Lower(Effect)

	Select Effect
		Case 0,"none"
			fade = 1.0
		Case 1,"blink"
			If fade < .5 Then 
				fade = 1
			Else
				fade = 0
			EndIf
		Case 2,"pulse"
			If Fade < .5 Then 
				Fade# = 1 - Fade
			EndIf
		Case 3,"charge"
			If fade < 1 Then
				fade = fade + fade / 5
			Else
				fade = 0
			EndIf
		Case 4,"fade"
			If fade > 0 Then
				fade = 1 - fade 
			Else
				fade = 1
			EndIf
	End Select

	Kolor = Lower(Kolor)
	Select Kolor
		Case "0","blk","black"							;Black
			Color 0,0,0
		Case "1","red"									;Red
			Color 255*Fade,0,0	
		Case "2","grn","green"							;Green
			Color 0,255*Fade,0
		Case "3","blu","blue"							;Blue
			Color 0,0,255*Fade
		Case "4","yel","yellow"							;Yellow
			Color 255*Fade,255*Fade,0
		Case "5","drd","dred","darkred"					;Dark Red
			Color 150*Fade,0,0
		Case "6","dgr","dgreen","darkgreen"				;Dark Green
			Color 0,150*Fade,0
		Case "7","dbl","dblue","darkblue"				;Dark Blue
			Color 0,0,150*Fade
		Case "8","dyl","dyellow","darkyellow"			;Dark Yellow
			Color 150*Fade,150*Fade,0
		Case "9","pur","purple"							;Purple
			Color 255*Fade,0,255*Fade
		Case "10","whi","white"							;White
			Color 255*Fade,255*Fade,255*Fade
		Case "11","gry","grey","gray"					;Grey
			Color 150*Fade,150*Fade,150*Fade
		Case "12","tel","teal"							;Teal
			Color 0,255*Fade,255*Fade
		Case "13","dgry","dgrey","dark grey","dark gray";Dark Grey
			Color 50*fade,50*Fade,50*Fade	
	End Select
End Function

Comments

virtlands2013
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:
http://tinyurl.com/ak6h49h {<-- List of colors, A-M}
http://tinyurl.com/ccmheyy {<-- List of colors, N-Z}

Color Names Supported by All Browsers:
http://www.w3schools.com/html/html_colornames.asp

ColorHexa List of Colors: { also contains color computer for HEX,RGB, CMYK, HSL, HSV, web-safe }
http://www.colorhexa.com/color-names

Cloford, 500+ named colors:
http://cloford.com/resources/colours/500col.htm

WorkWithColor:
http://www.workwithcolor.com/color-names-01.htm

Color Schemer is a website that offers color harmony and combinations.
http://www.colorschemer.com/blog/2007/07/24/140-named-colors/

Name that Color: {This website lets you input color codes, and it will do its best to name that color.}
http://chir.ag/projects/name-that-color/#BE798E

{ This also lets you find names of colors: }
http://www.colblindor.com/color-name-hue/

Huge Google Search of Color Names: http://tinyurl.com/co9g7ay
Huge Google Search of Color Charts: http://tinyurl.com/bnwtb8t

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.)
http://upload.wikimedia.org/wikipedia/commons/2/2b/SVG_Recognized_color_keyword_names.svg


-Rick-2013
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.


*2013
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-2013
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.


Code Archives Forum