Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot v3.2 Possible bug with randf() used in changing the hugh of a color. #35894

Closed
RichardR01 opened this issue Feb 4, 2020 · 3 comments
Closed
Labels

Comments

@RichardR01
Copy link

Godot version:
3.2
OS/device including version:
Windows 10 v1909
Issue description:
I don't know if this is a bug or is typical of a system randomizer function.
Changing the albedo color via hugh using the Color.to_hsv function using randf() tends to choose a very similar color or the same color on every other call. Though this isn't 100%, It is something I been trying to isolate. It seems to happen when calls to these functions happens frequently or fast.

I tried to prevent this from happening by comparing the current color and the previous color and using a bias so it would continue changing the color until satisfied. And what I see happen now is that the colors chosen seem to follow the same pattern after several calls to the function.

I have created a test project for this. Run it and click on the button and take note of the 2 cubes. The cube on the left is the previous color, the one on the right is the current. After several clicks of the button, perhaps you will notice what I am talking about.

I am using albedo_color.from_hsv(randf(), 1.0, 1.0) to change the color of the right cube. You will also notice in the script of the button, that I am testing for differences so the chosen color isn't close to the previous one. I am testing 2 biases because HSV starts and ends with red. Even still I see the same pattern emerge, sometime the current color will be blue and prevous orange (for example), next button press will be orange and previous blue, and 3rd buttonf press will be blue again and so on. Maybe it's just my imagination?

Steps to reproduce:
(just see the project.)

Minimal reproduction project:
TestProject.zip

@fossegutten
Copy link
Contributor

Seems pretty random to me. This while loop in your script causes fewer possible hues, so it might play some tricks on you?
Also, there is no reason to update the seed every time you click the button. This makes the randomize() in ready function pointless.

@groud
Copy link
Member

groud commented Feb 4, 2020

I see no problem too, it's likely your imagination, or the fact a random function is displaying the same sequence of number if you don't change the seed.

Closing as there is apparently no problem here. (But if someone actually find a problem due to the engine here, feel free to comment)

@groud groud closed this as completed Feb 4, 2020
@groud groud added the archived label Feb 4, 2020
@RichardR01
Copy link
Author

RichardR01 commented Feb 6, 2020

It was not my imagination when I saw it in my main project. Where the color generated directly using one of the random functions would sometimes generate the exact same color (or so close it's impossible to tell visually). It occured often enough for me to report it. But I wrote a new function that creates 4 colors and puts them into an array. Iterating through the array, I compare the hughs of the chosen color to the hughs of previously stored colors. If the difference is less than 0.8 I don't put it in and re-randomize another color and do the test again. If the test passes, it adds it to the array. So far It has worked very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants