首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尖叫圈部分

尖叫圈部分
EN

Stack Overflow用户
提问于 2011-12-07 02:22:00
回答 1查看 791关注 0票数 0

我正试着在Squeak-Smalltalk中用Morphic画一个四分之一的圆。它怎麽工作?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-07 03:02:12

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

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

更新2:使用四分之一圆的诀窍是让CircleMorph为您完成大部分工作!我想出的最好的结果是:

代码语言:javascript
复制
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的注释,但这是可能重构的信号:)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8404803

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档