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

Wierd behaviour on Burst count using rand function #246

Open
Sandstedt opened this issue Nov 3, 2020 · 3 comments
Open

Wierd behaviour on Burst count using rand function #246

Sandstedt opened this issue Nov 3, 2020 · 3 comments
Labels
bug bug to fix
Projects

Comments

@Sandstedt
Copy link
Member

Sandstedt commented Nov 3, 2020

When setting the burst count using the rand() function, the burst behaves wierdly, or random, too random. Sometimes the children are not spread out evenly, sometimes it's like the last childs is still playing. Compare this to when you set either count to, 2, 3, 4, 5 or 6 directly compared to 'rand(2, 6)'.

Example:

const example = new mojs.Burst({
  parent: '#example',
  x: 'rand(-50, 50)',
  y: 'rand(-50, 50)',
  count: 'rand(2, 6)'
});

document.addEventListener( 'click', function (e) {
  example.generate().replay();
});

Bug reproduction pen:
https://codepen.io/sandstedt/pen/Vwjdroy

@xavierfoucrier xavierfoucrier added the bug bug to fix label Nov 4, 2020
@xavierfoucrier
Copy link
Member

@Sandstedt Good catch! Looks like a bug 🐛

@xavierfoucrier xavierfoucrier added this to Bugs in mojs@next Nov 9, 2020
@AlexHRodrii
Copy link

AlexHRodrii commented Feb 5, 2023

This isn't a bug. There are two problems here @Sandstedt.

  1. When you use the rand function without truncating the result the rand function generates decimal values that causes the library to generate the particles in a wrong way.
  2. In the code you wrote the library will always generate the same number of particles when you click because the example constant is stored in memory and is not regenerated when you click the button.

The solution to your code and to get what you expected from the library is the following:

document.addEventListener( 'click', function (e) {
  new mojs.Burst({
  x: 'rand(-50, 50)',
  y: 'rand(-50, 50)',
  count: Math.floor(Math.random() * (6 - 2 + 1) + 2)
}).play().generate().replay();
});

@xavierfoucrier
Copy link
Member

@AlexHRodrii thanks for testing.

I haven't found the time to dive more into this issue, but from what I remember, it looks related to float stuff regarding the count property when using rand MoJS internal method.

I am keeping this open in order to investigate later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bug to fix
Projects
No open projects
Development

No branches or pull requests

3 participants