-
Notifications
You must be signed in to change notification settings - Fork 13
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
Tutorial: Big Ben #78
Conversation
This is beautiful! Looking forward to taking a closer look at the example! |
|
||
def get_envelope(self) -> Envelope: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed in the Big Ben tutorial that the under_arc
curve is chopped off when rendered. On closer inspection, it seems that there is a slight issue with the envelope. An arc can, in principle, be specified by negative angles:
arc(radius=1, angle0=-50, angle1=50)
but in the wrapped
function the direction d
takes only positive angles; so if a direction's angle is in the [310, ..., 360]
range then the if
condition enters through the second branch ("point outside of arc"). For the above example, the envelope looks like this (see the upper half of the envelope, which corresponds to the [-50, ..., 0]
range):
Oh, as always the Diagrams manual answers my questions.
|
I've made a small change to the computation of the arc's envelope. I hope I didn't break anything and it works fine now—is this the behaviour you would expect? arc(radius=1, angle0=-45, angle1=90) arc(radius=1, angle0=-45, angle1=360)
Yes, I have to fix this for arcs as well: currently, negative angles are in the top half and the arc is drawn clockwise... If we go with the counterclockwise convention, maybe we should have Edit: I think that swapping the angles and negating them draws the arc with the same convention as diff --git a/chalk/shape.py b/chalk/shape.py
index 62bfb30..6dbc980 100644
--- a/chalk/shape.py
+++ b/chalk/shape.py
@@ -255,6 +255,7 @@ class Arc(Shape):
angle1: float
def __post_init__(self) -> None:
+ self.angle0, self.angle1 = -self.angle1, -self.angle0
surface = cairo.SVGSurface("undefined.svg", 1280, 200)
self.ctx = cairo.Context(surface) |
Thanks. this is great, that was bugging me. (I am pushing a couple other tweaks I made as well, realize the colors are off in your version). Another related thing is that it would be nice if |
Yes, that's a good point! I've added an issue as a reminder. It might be also a good opportunity to allow for more flexible curves, such as Bézier curves or splines (as you suggested in #35). |
Gonna merge this in. Seems like it now fixes more than it breaks. Made issues for the remaining problems. |
Kind of an extended tutorial demo to replicate a diagram of the Big Ben clockface. Would love thoughts or comments for simplifying further.
https://srush.github.io/pydiagrams/examples/bigben/
Here's what it really looks like:
This is not ready to check in yet, as there are some major breaking changes. These include:
Sorry these probably should be different PRs, but most of them came up in the process of making the demo.