I'm trying to draw a quarter of a circle with Morphic in Squeak-Smalltalk. How does it work?
Thanks in advance!
I'm trying to draw a quarter of a circle with Morphic in Squeak-Smalltalk. How does it work?
Thanks in advance!
Copyright © 2021 Jogjafile Inc.
The best teacher is the the image itself. If you open a browser on CircleMorph, you'll see that its superclass, EllipseMorph, defines #drawOn:, which is how morphs draw themselves. From there, you can get all the information and inspiration to make your custom morph.
Update: My first thought was to draw it by hand (totally override #drawOn:), but there weren't any obvious candidates in Canvas. By letting the circle draw itself while setting the clipping rectangle to a quarter of it, it became almost a one-liner.
Update 2: The trick with a quarter-circle is getting CircleMorph to do most of the work for you! The best I came up with is:
Where QuarterCircleMorph is a subclass of CircleMorph. Because you can't draw past it's real bounds, everything works out. n.b. in actual code, the comments would be overkill (except maybe the 4x one, but then, that's a sign to maybe refactor :))