color question.

Blitz3D Forums/Blitz3D Beginners Area/color question.

Arvidsson(Posted 2009) [#1]
Im was playing around a little bit with this code when it hit me that if you scale upp a grayscale from zero and up it turns yellow when the value is about 10000. Not a problem really, just reset the counter at 255. Im just curious why ...

Is it problems with colors in general if you let the values get to high?

the code:

SCREEN_WIDHT = 800
SCREEN_HEIGHT = 480

UPDATE_SPEED = 200000

x# = (SCREEN_WIDHT / 2)
y# = (SCREEN_HEIGHT / 2)

Graphics SCREEN_WIDHT,SCREEN_HEIGHT
SeedRnd MilliSecs()

While Not KeyHit(1)

Cls

For i = 0 To UPDATE_SPEED
Plot x#,y#
x# = x# + Cos#(a) * Rnd(5)
y# = y# + Sin#(a) * Rnd(5)
a = a + Rnd(100,200)
If x# < 0 Or x# > SCREEN_WIDHT Then x# = (SCREEN_WIDHT /2)
If y# < 0 Or y# > SCREEN_HEIGHT Then y# =(SCREEN_HEIGHT /2)

r# = r# + 0.01
;g = g + 1
;b = b + 1
Color r#,r#,r#

If r >= 20000 Then r = 0

Next

Wend

End


Floyd(Posted 2009) [#2]
This happens because color values are not clamped to the range 0-255.
Blitz builds an RGB value from shifted R,G,B.

For example, a color value of 60000 results in red=green=234 and blue=96.

Graphics 500, 500, 0, 2

c = 60000

rgb = (c Shl 16) Or (c Shl 8) Or c

b = rgb And $FF
g = (rgb Shr 8) And $FF
r = (rgb Shr 16) And $FF


Print
Print "   Red = " + r
Print " Green = " + g
Print "  Blue = " + b

Color c,c,c
Rect 100, 100, 300, 200 

WaitKey



Arvidsson(Posted 2009) [#3]
Hmm okey.. good to know. Better look it up for future stuff. I tried another thing.

color r#,g#,b#

r# = r# + 0.01
g# = g# + 0.001
b# = b# + 0.0001

I had it running a while when doing some other stuff and when I came back there were only one red color printed on the screen ..


_PJ_(Posted 2009) [#4]
How long did you leave it for?

even on fast computers, the 10 0000 cycles or so needed to advance the blue component just by 1 would take some time.

Considering even say, RGB component of x looks almost identical to the human eye to a RGB component of x+1 or even x+5

The difference is easier to perceive if you can see the contrast against the original but alone it would be almost impossible to notice a change.

Are you sure you're updating the 'color' function in thie loop, are you re-drawing whatever it is?

A sample of the actual loop code might help see what the problem is.


Floyd(Posted 2009) [#5]
Floats have 24-bit precision. You are updating them as "number = number + increment".
They reach a maximum value of roughly (20,000,000 * increment).

This looks like it would run forever, but actually ends rather quickly.

Repeat
	x1# = x1# + 0.0001
	x2# = x1# + 0.0001
Until x1 = x2

Print "Final value is " + x1
WaitKey



Arvidsson(Posted 2009) [#6]
It was with the same code i posted at the first post.


jfk EO-11110(Posted 2009) [#7]
As far as I recall you can even use 24 bit hex colors in the Blue Channel:

color 0,0,$FF33AA


Ross C(Posted 2009) [#8]
Wasn't there some interesting things you could do in blitz3D with colour ranges greater than 255?


jfk EO-11110(Posted 2009) [#9]
Maybe you mean LightColor with Values from -255 to 0? Kind of darkening Beams. One of those things I spontanously have no use for, other than, maybe a black hole simulation :)