Skip to main content
Engineering LibreTexts

11.3: Composing Morphs

  • Page ID
    36392
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    One way of creating new graphical representations is by placing one morph inside another. This is called composition; morphs can be composed to any depth. You can place a morph inside another by sending the message addMorph: to the container morph.

    \(\bigstar\) Try adding a morph to another one:

    star := StarMorph new color: Color yellow.
    joe addMorph: star.
    star position: joe position.
    

    The last line positions the star at the same coordinates as joe. Notice that the coordinates of the contained morph are still relative to the screen, not to the containing morph. There are many methods available to position a morph; browse the geometry protocol of class Morph to see for yourself. For example, to center the star inside joe, execute star center: joe center.

    The star is contained inside joe, the translucent blue morph.
    Figure \(\PageIndex{1}\): The star is contained inside joe, the translucent blue morph.

    If you now try to grab the star with the mouse, you will find that you actually grab joe, and the two morphs move together: the star is embedded inside joe. It is possible to embed more morphs inside joe. In addition to doing this programmatically, you can also embed morphs by direct manipulation.

    \(\bigstar\) From the world menu select “objects” and click on the button labeled “Graphics”. Drag an ellipse and a star from the Supplies flap. Place the star over the ellipse, and yellow-click the star to bring up a menu1. Select embed into ⊳ Ellipse. Now the star and the ellipse move together.

    To remove a sub-morph, do joe removeMorph: star or star delete. This can also be done by direct manipulation:

    \(\bigstar\) Blue click twice on the star. Drag the star away from the ellipse using the grab handle.

    The first click brings up the morphic halo on the ellipse; the second click the halo on the star. Each click moves the focus down one level of embedding.


    1. You can also blue-click the star to bring up the morphic halo, and then click the red menu handle.


    This page titled 11.3: Composing Morphs is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz, Damien Pollet via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.