quil/rotate rotates around [0 0] point, right? How can I rotate eg a rectangle in-place, i.e, around/relative to it's center?
The problem with translation is that I need to know the actual coordinates of a primitive, before rotation, every time. This is not helpful when drawing within mapv or similar
AND it does not work for ellipse..
@srijayanth Can you elaborate on the center mode, can't find it in the api
It controls how arguments to rect are interpreted. It doesn't affect the rotation point though.
Great, that helps a bit. What about other shapes, like triangle and vertex?
Only ellipse (`ellipse-mode`) is supported. Regardings triangle, there are more than 70k of definitions of triangle https://faculty.evansville.edu/ck6/encyclopedia/ETC.html... The same probably applies to any other (not symmetrical) shape.
Generally you may want to find a center of the shape enclosing circle. But it's not trivial in general.
The simplest solution so far for me is to use (q/with-translation [] (q/with-rotation [] combo, with the :center mode. But the triangles are off as expected, as you can see on the image, returned by a mapv sequence.
Here it's more clear : )
Depends what you expect. And how you define the center of the triangle.
What about inducing the size of the rectangle surrounding a shape and rotating it/the whole canvas in closure?
Doable. If you are on JDK, take a look at PShape which knows enclosing box size.
If I understand you correctly, I can use Pshape with quil via interop, right?
I am not bit on java interop, how can I access it?
Hmmm... In Processing you cal call createShape I don't see such function in quil. It's explained here: https://github.com/quil/quil/issues/165
Maybe the easiest way is to calculate the centroid of used vertices and rotate around it. Centroid is just an average of point coordinates (x and y separately).
Thanks everyone for help!
translate to the center of the rectangle, rotate and translate back
there are two ways
One is to calculate the points yourself and draw, which is painful
But here is a useful snippet
(q/with-translation [(+ x half-width) (+ y half-height)]
(q/rotate angle)
(q/translate (- half-width) (- half-height))
(q/rect 0 0 width height))
Thank you all. It seems to be quite a chore for such a simple operation ) Is there anything standard in the core quil lib? I guess might others have the same question
Get used to it :) It works this way in most of such libraries. With rotate/translate/scale/shear you build affine transformation of your plane. This way shapes and tranformations are separated and can be composed.
I highly recommend drawing by hand until you get a hang of it, it becomes a lot easier then
Alternately, you can use the center rect-mode and it’ll save you one translate call…