| rotatePoint calcPoints mergePoints starPoints | rotatePoint := [ :x :y :rad | ((rad cos * x) - (rad sin * y)) @ ((rad cos * y) + (rad sin * x))]. calcPoints := [ :r | (0 to: 8/5 by: 2/5) asOrderedCollection collect: [:each | rotatePoint value: r value: 0 value: (each * Float pi)]]. mergePoints := [ :outer :inner | | points | points := OrderedCollection new. 1 to: outer size do: [ :i | points add: (outer at: i). points add: (inner at: i)]. points]. starPoints := [ : r | | outerPoints innerPoints | outerPoints := (calcPoints value: r) collect: [ :p | p rotateBy: (Float pi / 2) about: 0 @ 0]. innerPoints := (calcPoints value: r / 2) collect: [ :p | p rotateBy: (Float pi / 4) about: 0 @ 0]. mergePoints value: outerPoints value: innerPoints]. (PolygonMorph vertices: (starPoints value: 20) color: Color yellow borderWidth: 2 borderColor: Color black) openInHand
PharoByExample のモーフの章で StarMorph が出てくるのですが Pharo 6.1 (stable) には実装されていないようなので、作ってみました。
ワークスペースに貼り付けて Do It すれば、星モーフ(のように見えるポリゴンモーフ)が現れます。ちょっといびつですが、それはご愛嬌ということでw