-
Notifications
You must be signed in to change notification settings - Fork 120
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
push_matrix() and pop_matrix() not working #156
Comments
The syntax in the tutorials is incorrect. Instead of: It should be: |
I can't reproduce this. When I run the above code, with proper indenting, and with a correct
I get: That is correct (equivalent to output in Processing, Processing.py, et cetera) |
I kind of made a mistake while copying the code. Here is the code: I don't know how to add indentation to code here. |
Format you code by highlighting it and pressing Your second code does show an error (although your "this is the output in processing, processing.py" is incorrect, it doesn't matter). I can reproduce a problem with
|
Can you share the result for your code in processing? I would really like to know what did i do wrong while writing in processing.py. It would be nice if you could share the code as well as the output |
Sure, but then we should move this discussion to the forum: https://discourse.processing.org GitHub issues aren't the best place for coding help discussions. The changes to make are:
As you can see, the third rect is green. In your drawing it is gray. I'm not sure what you did. If you want to write idiomatic processing.py, you can also make pushMatrix() a self-closing context manager using
This produces the same image output as above. |
As far as the issue is concerned, using
does solve the issue |
Huh. It produces correct behavior, yes. But the issue you found is pop_matrix() not working -- it doesn't solve that issue. |
Hmm. Looking at the documentation here: https://github.com/p5py/p5/blame/master/docs/guides/for-processing-users.rst
In processing.py pushMatrix() can be used either as a context manager() or to push with a manual pop, in the Java style. If manual push_matrix() in p5py isn't implemented in the non-context-manager way, it looks like the issue might be that |
See #147 |
i went through the code and this is how pop_matrix is implemented:
As you pointed out it needs to be dropped as it seems to be redundant
push_style is also implemented as a context-manager, so it will be used as follows:
|
Is this true of Edit Never mind, looks like push and pop aren't implemented -- I was seeing only seeing them in code search due to a javascript web preview. |
Can i fix this issue? |
Hi @tyagi619 -- could you test / code review the PR that I posted? Unless you suggest a different approach? |
i guess i can |
Did you want to do something else instead, or your own PR? |
@tyagi619 -- would you prefer that I withdraw my PR so that you can submit your own? |
that would be great |
We can use a stack to store the transformation matrix whenever push_matrix() is called and then pop from the stack whenever pop_matrix() is called. Would it be better this way or should I just remove the pop_matrix() ? |
I think just remove pop_matrix, and clean up the reference and documentation accordingly, as per:
This was what I modeled in my PR and originally requested your review. @parsoyaarihant @abhikpal -- do you think p5 should implement both Note that using pop_matrix as a context manager as implemented already creates a de-facto stack -- the call stack. You can see recursively nested calls creating a matrix stack ~5-deep, here:
|
Just let me know which way you would prefer and i would do it accordingly |
@jeremydouglass i will do the updates by tomorrow |
Hi @tyagi619 -- are you still planning on opening a PR for this? |
using pop_matrix() does not restore the transform matrix to the previous state. I tried using the exact codes mentioned in your documentation : https://p5.readthedocs.io/_/downloads/en/latest/pdf/.
from p5 import *
def setup():
size(200, 200)
def draw():
background(255)
fill(192)
no_stroke()
rect((40, 40), 40, 40)
push_matrix()
translate(40, 40)
rotate(radians(45))
fill(0)
rect((40, 40), 40, 40)
pop_matrix()
if name == 'main':
run()
The following code clearly depicts the error
The text was updated successfully, but these errors were encountered: