Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Sunrise

Author
Message
FireIndy
17
Years of Service
User Offline
Joined: 17th Jan 2007
Location: US of A
Posted: 8th Feb 2009 21:54
Im stuck xD. Im using Cucumber's day night cycle as an outline for mine in my game. It works well btw

http://forum.thegamecreators.com/?m=forum_view&t=82473&b=6

What Im trying to do is incorporate a Sunrise right now. You know all those purple colors that come up as the sun does. Here's the sunrise code I tried to put together:


Purple is a variable I have set to 20.



What I want to happen is the backdrop color change from the blue1 variable to more of a purpleish color. Then when it reaches the other height, I want that purple to fade away. I know the second if statement is totally out of wack, because Im trying to first get the purple to fade in first. Then Ill worry about it fading out back to blue.

If anyone could help me on this, Id really appreciate it. (Im also sick today, so that doesnt help my programming lol)


Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Feb 2009 20:22
I'm not sure what your doing but this sounds like a gradient issue. I tried just using color values to advance from one color to another but found it didn't work. However, I did figure out what works for me. When moving from one color to another over a given number of steps you have to work with the individual RGB values.

I developed class that generates gradient values by providing beginning and ending colors and the number of steps. Each tine you'd need the next value you'd just ask for it and the gradient object would return the next value in the gradient. Unfortunately I don't seem to be able to find my source code at the moment.

So I'll be a bit vague here for now. I've used ints but for the sake of keeping unsigned 32 bit values I'll illustrate using DWORDs.

DWORD startColor;
DWORD endColor;
int steps;
int stepNumber = 0;

DWORD startRed;
DWORD startGreen;
DWORD startBlue;
DWORD endRed;
DWORD endGreen;
DWORD endBlue;

float redSlope;
float greenSlope;
float blueSlope;

Assuming that startColor, endColor and steps have been entered and you've extracted the start and end values of the red, green and blue components into the appropriate values.

redSlope = ((float) endRed - (float) startRed)/ (float) steps;
greenSlope = ((float) endGreen - (float) startGreen)/ (float) steps;
blueSlope = ((float) endBlue - (float) startBlue)/ (float) steps;

DWORD currentRed = startRed + stepNumber*redSlope;
DWORD currentGreen = startGreen + stepNumber*greenSlope;
DWORD currentBlue = startBlue + stepNumber*blueSlope;

return (DWORD)((255 << 24) | (currentRed << 16) | (currentGreen << 8) | currentBlue);

Note that I've dropped some type casting for bevity. Each time you're ready to change the color you just advance the value of stepNumber and calculate the new color. Just make sure that stepNumber is never greater than steps. It probably wouldn't hurt your program but could give you some strange colors.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office

Login to post a reply

Server time is: 2024-09-30 17:27:49
Your offset time is: 2024-09-30 17:27:49