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
angleMode() and degrees() / radians() #163
Comments
I cannot imagine why degrees(PI) should ever return anything other than 180. Also angleMode isn't part of the processing API as of now, is it necessary/helpful? |
@brysonian angleMode is a nice way to think about angles for some students, also, Khan academy uses it in their curriculum and they are considering switching to p5.js, so it was a request from them. |
@shiffman so |
yep, radians is in there already, too! |
Great, I'm happy to make this change to Does anyone know how the proper JS way to get access to the p5's current angle mode in the PVector object? I'll need it for |
Maybe we should make |
not sure, but you can try to get the p5 object, before the PVector constructor: (i think it is better to avoid using globals, unless in global mode, or that would be worse, later..!) |
sorry no. it won't work. the |
yeah, I found the same thing. having a similar problem trying to get access to constants in the unit tests. will think about it some more... |
i think we need a reference to the current instance of p5 (not only the constructor) always available after it has been created. PVector (and any other constructor used within p5) could be a constructor method of p5.prototype, with a global reference for convenience. |
I think @taseenb's proposal (for PVector to be a constructor method of p5.prototype) makes sense for gaining access to the p5 instance. However, my one concern is that I think it is useful for PVector to exist on its own as a stand-alone object/prototype. For example, would there ever be a case where you want to create PVector instances without there being an actual p5 instance? I think so, there is no conceptual need for a vector to be tied to p5. A vector is just numbers and some math operations. So, is the following possible?
So far I believe all we need from the instance is
|
@shiffman sure, i see what you mean. but PVector can be added as method of p5 and exposed to the global context at the same time. just an alias. sure, it will behave differently, because the global version won't have access to any sketch data. but, as you say, you can easily manage both cases. concerning the instance of p5, it probably deserves a more general discussion, since it involves how the instances of p5 can/should expose the prototype. this in important because, this may be how to create plugins and extend p5. [EDIT : solution improved, without
we would be able to extend the library by creating plugins (and also mix global and local objects, if needed in some particular cases like PVector):
|
@evhan55 do you have thoughts about this solution? should I try to implement something like this or do you want to do it since you've been working on core recently? |
@lmccart @evhan55 as you may have noticed, there is at least one mistake in my example: ie, i simplified too much the |
i made a gist: https://gist.github.com/taseenb/9941545 the cleanest solution i see in javascript is to remove the
|
@taseenb Thank you, this is looking great. I would like to try to incorporate this suggestion into core to practice with PVector and see how it feels to have it as an I have a couple of other tasks to do in core first, and then I will attempt this. @shiffman @lmccart how does the plugin solution sound to you? |
Thinking out loud about
degrees()
andradians()
. Should these methods depend on the current "angle mode"? In other words, at the moment the following two snippets produce different results.I wonder if you are calling
degrees()
you really always mean to do that conversion while other methods that act on an angle (rotate()
,PVector.fromAngle()
, etc.) of course act according to the current "angle mode".I am not sure about this one.
The text was updated successfully, but these errors were encountered: