正方形と正三角形のクイズの図を描く

解くんじゃないのかよ!w


ヒビルテ より。おそらく、中学校の幾何の問題。

| pasteboard triangle square anotherTriangle |

pasteboard := RectangleMorph new.
pasteboard color: Color white.
pasteboard borderWidth: 0.

square := PolygonMorph
   shapeFromPen: [: pen |
      pen north.
      4 timesRepeat: [pen go: 100; turn: -90]]
   color: Color transparent
   borderWidth: 1 
   borderColor: Color black.

pasteboard topLeft: square topLeft - 50 asPoint.
pasteboard addMorph: square.

triangle := PolygonMorph
   shapeFromPen: [: pen |
      pen north.
      3 timesRepeat: [pen go: 100; turn: 120]]
   color: Color transparent
   borderWidth: 1
   borderColor: Color black.

pasteboard addMorph: triangle.
pasteboard extent: pasteboard submorphBounds extent + 100 asPoint.

{  square topRight. square bottomLeft.
   square topLeft. triangle vertices third
} pairsDo: [: point1 : point2 |
   pasteboard addMorph: (LineMorph from: point1 to: point2 color: Color black width: 1)].

"anotherTriangle := triangle copy.
anotherTriangle align: anotherTriangle vertices first with: square vertices fourth.
anotherTriangle borderColor: Color red.

pasteboard addMorph: anotherTriangle.

pasteboard addMorph: (LineMorph
   from: anotherTriangle vertices third
   to: triangle vertices third
   color: Color red width: 1)."

pasteboard openInWorld


後半にあるコメントアウト("...")を復活させると、補助線も描画します。w