Color Shading

Blitz3D Forums/Blitz3D Beginners Area/Color Shading

Chalky(Posted 2006) [#1]
I am trying to write a routine that creates "3d" buttons in 2d via a single function which is passed red, green and blue values. My intention is to have the function automatically generate the required colors to lighten the left/top edge and darken the bottom/right edge. I therefore need to be able to create any shade of a given color from very dark (almost black) to very light (almost white). Despite much brain cell scratching, I have not been able to achieve this. I have got this far, which does not work:

r#=5
g#=167
b#=119

rd#=r#/100
gd#=g#/100
bd#=b#/100

For k#=5 To 250 Step 5
	Color k#*rd#,k#*gd#,k#*bd#
	Rect x%,y%,32,32,1
	If k#=100 Then ; orig color
		Color 255,255,255
		Rect x%,y%,32,32,0
	EndIf
	x%=x%+32
	If x%=320 Then 
		x%=0
		y%=y%+32
	EndIf
Next

WaitKey
End


I am very new to working with color palettes - can anyone please give me any pointers as to what I am doing wrong?


mindstorms(Posted 2006) [#2]
There is something like this elsewhere, in the code archives under graphics maybe...

In general I think it would be needed to write pixel by pixel, then storing the product in an image. perhaps find the distance between the starting pixel and the current pixel then color it accordingly (a = y1-y2, b = x1-x2, dist = sqrt(a*a+b*b))...There is probably a better way somewhere, these are just some thoughts.


Chalky(Posted 2006) [#3]
Well I did a two hour trawl thru the archives but couldn't seem to find anything similar other than gradients. It's possible that gradient code has the answer, but I was hoping to be able to code something which generated a lighter color that was, say, 50% brighter than the initial value, and likewise a darker one that was 50% less bright. I therefore need to be able to calculate any rgb values to generate colors from black to white which pass thru the supplied color. I'll keep trying...


b32(Posted 2006) [#4]
Hmm, I don't know, I think it is best to find something about calculating hue/saturation/lightness on internet, but this program goes from black to a color and then to white:



Chalky(Posted 2006) [#5]
bram32, that is exactly what I was looking for - I would never have worked that out in a million years - thank you!