吱吱圈部分
我正在尝试使用 Squeak-Smalltalk 中的 Morphic 绘制四分之一圆。 它是如何运作的?
提前致谢!
I'm trying to draw a quarter of a circle with Morphic in Squeak-Smalltalk.
How does it work?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的老师是图像本身。如果您在 CircleMorph 上打开浏览器,您将看到它的超类 EllipseMorph 定义了 #drawOn:,这就是变形绘制自身的方式。从那里,您可以获得制作自定义变形的所有信息和灵感。
更新:我的第一个想法是手动绘制它(完全覆盖#drawOn:),但 Canvas 中没有任何明显的候选者。通过让圆圈自行绘制,同时将剪切矩形设置为其四分之一,它几乎变成了一条直线。
更新 2:四分之一圆的技巧是让 CircleMorph 为您完成大部分工作!我想出的最好的办法是:
其中 QuarterCircleMorph 是 CircleMorph 的子类。因为你无法超越它的真实界限,所以一切都会顺利。注意,在实际代码中,注释可能有点过分了(除了 4x 的注释,但是,这可能是重构的标志:))
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 :))