吱吱圈部分

发布于 2024-12-19 23:40:35 字数 74 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾北清歌寒 2024-12-26 23:40:35

最好的老师是图像本身。如果您在 CircleMorph 上打开浏览器,您将看到它的超类 EllipseMorph 定义了 #drawOn:,这就是变形绘制自身的方式。从那里,您可以获得制作自定义变形的所有信息和灵感。

更新:我的第一个想法是手动绘制它(完全覆盖#drawOn:),但 Canvas 中没有任何明显的候选者。通过让圆圈自行绘制,同时将剪切矩形设置为其四分之一,它几乎变成了一条直线。

更新 2:四分之一圆的技巧是让 CircleMorph 为您完成大部分工作!我想出的最好的办法是:

QuarterCircleMorph>>drawOn: aCanvas

    | realBounds |
    "Save the actual bounds of the morph"
    realBounds := bounds.

    "Pretend the bounds are 4x as big"
    bounds := bounds bottom: bounds bottom + bounds height.
    bounds := bounds right: bounds right + bounds width.

    "Let CircleMorph handle the drawing"
    super drawOn: aCanvas.

    "Restore the actual bounds"
    bounds := realBounds.

其中 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:

QuarterCircleMorph>>drawOn: aCanvas

    | realBounds |
    "Save the actual bounds of the morph"
    realBounds := bounds.

    "Pretend the bounds are 4x as big"
    bounds := bounds bottom: bounds bottom + bounds height.
    bounds := bounds right: bounds right + bounds width.

    "Let CircleMorph handle the drawing"
    super drawOn: aCanvas.

    "Restore the actual bounds"
    bounds := realBounds.

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 :))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文