-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Implementation of new functions setRandom2D() and setRandom3D() in p5.Vector #6145
Conversation
Pass a reference to random() when creating a vector with createVector().
Rewrite the constructor so that it registers a reference to p5.js random() when created with createVector(). Rewrite copy() accordingly. cross() also needs to be rewritten, but the second half of the process overlaps with copy(). So I'll leave that to copy().
Implement setRandom2D(), setRandom3D(). no arguments, Chainable.
remove trailing spaces
Minor fixes such as semicolons.
Fix TWO_PI to constants.TWO_PI.
Wrong call to fromAngle() on Random2D. The function called this.fromAngle when it should have called p5.Vector.fromAngle(). However, rather than correcting this, it would be easier to write using a newly created function and rewrite it accordingly, so I fixed it that way.
I thought it was a bug, but I was wrong... That aside, I modified random2D() and random3D() because it's easier to write using the newly created functions. |
Since vectors created with createVector() and vectors created with new p5.Vector() have slightly different properties, I thought it would be better to clarify that.
Since vectors created with createVector() and vectors created with new p5.Vector() have slightly different properties, I thought it would be better to clarify that. |
Fixed some notation for spacing.
As for the example, I would like to replace it with a simpler one that just confirms the effect of randomSeed(). |
I have simplified my comments by narrowing down the topic.
Simplified examples of setRandom2D() and setRandom3D().
It may be better to increase the parameters so that the range can be specified. |
Since the issue is open, I think I'll open it as well. |
The reason is as written in the issue. I would like to close this pull request. |
Among the functions that obtain random values, functions such as shuffle() and randomGaussian() are affected by randomSeed() because they use p5.js random() internally.
However, p5.Vector's random2D and random3D functions are static, so p5.js's random() cannot be used and the seed value cannot be fixed.
Therefore, I thought it would be nice to have a function that can obtain such a random unit vector with a fixed seed value, so I decided to propose an implementation.
Resolves #6141
Changes:
Implements functions that operate on vectors and set their components to a 2D or 3D unit vector. A unit vector is chosen randomly. In the 2D case, only objects with a z component of 0 are selected.
Pass a reference to random() in p5.js when the p5.Vector is created with createVector(). As a result, when applying this function to a vector prepared by createVector(), the p5.js function random() is used. For example, it will be affected by randomSeed().
example
for setRandom3D():
PR Checklist
npm run lint
passes