This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-07
Channels
- # announcements (20)
- # babashka (25)
- # beginners (48)
- # biff (26)
- # calva (5)
- # cider (3)
- # clara (7)
- # clerk (7)
- # clj-kondo (61)
- # cljdoc (3)
- # clojure (6)
- # clojure-austin (1)
- # clojure-conj (8)
- # clojure-europe (58)
- # clojure-nl (1)
- # clojure-norway (4)
- # clojure-poland (1)
- # clojure-uk (9)
- # cursive (2)
- # emacs (11)
- # fulcro (8)
- # graphql (14)
- # gratitude (6)
- # humbleui (10)
- # hyperfiddle (17)
- # integrant (15)
- # introduce-yourself (1)
- # leiningen (5)
- # malli (13)
- # meander (21)
- # nbb (11)
- # off-topic (15)
- # pedestal (15)
- # polylith (15)
- # quil (28)
- # rdf (2)
- # reitit (3)
- # releases (6)
- # sci (21)
- # shadow-cljs (38)
- # spacemacs (3)
- # xtdb (6)
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?
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…
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..
@U8VE0UBBR 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.
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.
What about inducing the size of the rectangle surrounding a shape and rotating it/the whole canvas in closure?
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