Organization of an idea.

BlitzMax Forums/BlitzMax Beginners Area/Organization of an idea.

Ryan Burnside(Posted 2007) [#1]
Hi,
I would like to impliment a system into my game that shifts the color based on the user's current time of day.

currently I use a function that finds the average between two colors and sets the color based on the multiplier variable. How would I make more than two colors used per day?

Say I had X number of color points. How would I find the proper color based on the time of day?

Basically I draw a transparent rectangle over the screen to give the impression of a global lightsource. This tints the whole screen and can give cool effects.

Sorry if this is unclear, most of my games are more abstract art based.....




tonyg(Posted 2007) [#2]
24 hours or 1440 minutes in a day.
That means the RGB value changes 0.18 per minute.
Take the start RGB from 00:00, determine current time, work out the difference in minutes and the start RGB values by the RGB change factor. When RGB reaches 255 loop to 0.
If I have understood correctly...


Ryan Burnside(Posted 2007) [#3]
My code currently only allows for 2 colors where the first is 00:00 and the last is 23:00. How would I make a similar code that used say a list of color objects to find the color of the time based on the color objects?

Strict
Graphics 640,480

Function setdaycolor(r#,g#,b#,r2#,g2#,b2#,percent#)
	Local r_dif#=r2-r
	Local g_dif#=g2-g
	Local b_dif#=b2-b
	SetColor r+(r_dif*percent),g+(g_dif*percent),b+(b_dif*percent)
End Function
Local time=0

While Not KeyDown(Key_escape)
	Cls
	
	setdaycolor(255,255,0,0,0,128,Float(CurrentTime())/23)
	DrawRect(MouseX(),MouseY(),320,240)
	Flip
WEnd



H&K(Posted 2007) [#4]
You do exactly what you are already doing, then when it reaches the second colour, do it again.


ima747(Posted 2007) [#5]
I was actualy just thinking about this for a hitpoint bar in a game I'm working on. I haven't implimented it yet but here's the concept I've got so far.

Do just what you have to get the color between 2 points. but set each point at a certain value. That's not very clear so I'll try with more detail using hitpoints as an example.

You have 100 to 0 hp
from 100-80 is one segment changing from say green to yellow. That's a 20point range so each point is 5% (5% * 20 = 100%) . If your current Hp is say 95 out of 100. it's above 80 so we use this HP color segment (instead of the 80-60 segment, or whatever other segment) 95-80 = 15. 15 is 75% of 20 so find 75% of the color (using your current method) between the color for 100 and the color for 80.

This requires you to assing a point along your line, and a color to each point. To make it more specific for your time system, 00:00 is point 0, color at point 0 is green. 01:00 is point 1 (if you're going hourly) and color is blue. time is 00:45. that is between points 0 and 1 so we used the colors for 0 and 1. it is 75% of the way to the second color so use your color finding function to find 75% of the color of point 0 (green) and point 1 (blue) and there you go.

Something tells me there is a more elegent way to find that than an array which is what I would use, but that will work.

Of note, the points do not have to be evenly spaced, as you are finding the % difference between 2 points. you simply have to know where those points are and what colors you want to use if something is perfectly on the point.

If you have already come up with a cleaner solution I would be interested if you would like to share it.


skidracer(Posted 2007) [#6]
I would use a palette object and store the entire day by calling the setrange method multiple times:
Type TPalette
	Field r[256]
	Field g[256]
	Field b[256]
	
	Method UseColor(n)	
		SetColor r[n],g[n],b[n]
	End Method
	
	Method SetRange(lo,r0,g0,b0,hi,r1,g1,b1)
		Local i,d
		d=hi-lo		
		For i=0 To d
			r[lo+i]=r0+(r1-r0)*i/d
			g[lo+i]=g0+(g1-g0)*i/d
			b[lo+i]=b0+(b1-b0)*i/d
		Next
	End Method
End Type