Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Loyette

Pages: [1]
1
General / Re: How to fade from one colour to another colour?
« on: July 14, 2018, 05:34:34 pm »
I found a solution :D

Firstly, here's the results:

Transition from orange to white: https://i.imgur.com/1HkZYm8.png?1

Transition from orange to blue: https://i.imgur.com/Z0hnf30.png?1

Turned down the rate so we can see how the colours change: https://i.imgur.com/SIGQJUw.png?1

I don't really think there were too many artifacts and I also did my interpolations entirely in RGB without converting between HSV and RGB (although, I read that converting to HSV produces better results, so I'll probably implement this later at some point).

If anyone in the future is reading this and asking the same questions as me with the fading colours, here's the code I used to do it:

particles[i].colour.r = (255 - particles[i].colour.r) * rate + particles[i].colour.r;
particles[i].colour.g = (255 - particles[i].colour.g) * rate + particles[i].colour.g;
particles[i].colour.b = (255 - particles[i].colour.b) * rate + particles[i].colour.b;
 

The rate is a float. I have set the rate at 0.02, though for the third image it was set at 0.009.


The formula I found was:

currentColour = (targetColour - currentColour) * rate + currentColour

As you can see in the code this is used 3 times for r, g and b.

2
General / How to fade from one colour to another colour?
« on: July 14, 2018, 02:57:10 pm »
Hi,

I'm looking to add a feature to my particle system that fades a particle from being one colour to being another colour.

Currently, my particles have an attribute called 'percentLife'. PercentLife is used to make the particles fade out and shrink before they are deleted (to make the deletion more seamless and make them not appear as if they vanish instantly).

particles[i].colour.a = particles[i].percentLife * 255;
particles[i].particleSprite.setColor(particles[i].colour);

particles[i].scale = particles[i].scale * particles[i].percentLife;
particles[i].particleSprite.setScale(particles[i].scale);
 

As you can see, I'm just using percentLife in order to morph the scale and alpha so that it fades and shrinks for when it dies. Percent life starts at one and goes down to 0 throughout the particle's lifetime.

I want to implement a similar system but so that, for example, a colour can morph from blue to yellow. I've been having a lot of trouble doing this and I think I might be missing some maths on how this is done.


How is this done? I've been trying to work it out but I'm at a loss.

Thanks :)

3
General / Re: SFML event not working
« on: April 02, 2017, 07:45:12 pm »
You pass the event to the function.

Please could you give an example? I've tried literally everything, including making all the variables accessible to both classes, but it still doesn't work. It doesn't seem to actually be calling my eventKeyPress function

4
General / SFML event not working
« on: April 02, 2017, 04:27:05 pm »
I want to have my program so each event is handled by a method in a separate class. These methods are then called in my main loop. Here's my code. I literally just started SFML so this is copied off the tutorial:

                while (source.window.pollEvent(event))
                {
                        if (event.type == sf::Event::TextEntered)
                                eventHandle.eventKeyPress();

                        // Close requested event = close the window
                        if (event.type == sf::Event::Closed)
                                source.window.close();
                               
                }

I have a variable called eventHandle. Here is the method eventKeyPress:

                        if (source.event.text.unicode < 128){
                        std::cout << "ASCII character typed: " << static_cast<char>(source.event.text.unicode) << std::endl;
                        source.shape.move(sf::Vector2f(50, 0));

        }

As you can see, I've literally put what I want the event to do inside that method.

I did some testing in debug mode and I know why it's not working, but I don't know how to fix it. So in my main() I have defined the variable:

sf::Event event;

I'm using that in my main function, but I'm using a different variable in my 'eventKeyPress'. I tried putting 'sf::Event event;' in the source.h class, but it really didn't like it. The computer only likes it if I have the 'sf::Event event;' inside my int main() function.

How do I fix my problem?

Pages: [1]
anything