-
Notifications
You must be signed in to change notification settings - Fork 10
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
Shape rotation #70
Comments
@eXodiquas The odd direction was caused by an old bug in However, I have changed the transformation in I still need to check that the behaviour matches Processing. Here is an example program:
|
Oh now I see why my draw method had the strange behaviour of moving the shape around each frame. Coordinate systems are hard. 🧠 I tried a program in sketching and in processing: void setup() {
size(600, 400);
background(230);
}
void draw() {
background(230);
int fc = frameCount;
PShape p = createShape();
p.beginShape();
p.vertex(0, 0);
p.vertex(50, 50);
p.vertex(50, 0);
p.endShape();
fill(255, 255, 0, 255);
shape(p, 300 + fc, 200);
p.rotate((22.5/180) * 3.1415);
translate(50, 0);
fill(255, 0, 0, 255);
shape(p, 300 + fc, 200);
} #lang sketching
(define (setup)
(size 600 400)
(background 230)
)
(define (draw)
(background 230)
(define x frame-count)
(define s (new Shape))
(s.begin-shape)
(s.vertex 0 0)
(s.vertex 50 50)
(s.vertex 50 0)
(s.end-shape)
(fill 255 255 0 255)
(s.draw (+ 300 x) 200)
(s.rotate (* (/ 22.5 180) 3.1415))
(translate 50 0)
(fill 255 0 0 255)
(s.draw (+ 300 x) 200))
and both programs are behaving differently here, but none feels "wrong". The processing one only draws red shapes, based on the last Is there anything else left to do in regards of bug fixing of my code? |
@eXodiquas Yep. Coordinate systems are hard. It didn't help that I was a long time to discover There is one thing, I thought of when reading the source code.
The question is whether the children of a group are rotated when the group is rotated. If it is simpler, then test the above with translation instead of rotation. |
I'll check out your example in Processing. Let's see if we can figure out what causes the difference. Btw - do you know wheter P5.js has shapes as objects? |
Your Processing examples is interesting. If I add the line
right before the line
then the shape gets blue as the fill color. The subsequence Now it sort of makes sense P. uses the current fill color when the shape is created. |
I think, I figured it out. Each shape stores a "style" which (sigh) "include attributes such as colors, stroke weight, and stroke joints". Calling "disableStyle()" makes shape drawing uses the standard current fill and stroke. The documentation of
That is, when It also explains why both triangles in your example get the same color (except for the very first frame). It even explains why the color is the last one. The last fill color is still active when There are still some details to work out: Which attributes are stored as part of the "style". |
Turns out a style contains almost all settings of the drawing context. https://github.com/processing/processing4/blob/master/core/src/processing/core/PShape.java#L319 |
Regarding the test program, I'll give it a shot tomorrow. I try to replicate as many edge cases as possible and compare it to the Processing version of the same code. Do you want me to push it to the Repo under a test directory or just a link to a gist in this issue?
So that's what the style is all about. Should this be a thing in Sketching aswell? It seems like it is just a shortcut for "I don't want to define the style specifically for each shape, so I use the global style." But Sketching is already doing this if no specific value is set for a style (at least for fill as stated above).
I'm pretty sure p5.js does not have shape objects, I tried to create those examples in an web editor first and I did not find anything about shape objects, only workarounds. I had to install Processing to check the behaviour. |
Yes, give it a shot. I think the best way to do it, is to make a new branch in your repo. Wrt to style: You already have some of the state of a style (the fill and stroke). I think you are right about P5.js not having a Shape class. |
I am currently writing the test program and I found a big difference between Sketching and Processing. In Processing it is only useful to add child shapes to parent shapes that are defined as Before I start fixing this, I'll compile a list of differences I found while writing the test programm, so we can generate a list of issues. |
@ericcervin Thanks for the bug report! Turns out there was a mistake in Note that the "use translate to change the origin to the point of revolution before calling rotate" is part of the processing manual too. When I have commited a bug fix. Let me know if it works. |
@eXodiquas
When shapes are rotated the x and y the
draw
method shouldn't transform the placement coordinates.In the example below I was surprised by the direction of the second shape.
The text was updated successfully, but these errors were encountered: