[squeak-dev] Rotating Morphs; how to rotate about a point other than the centre of bounds?

tim Rowledge tim at rowledge.org
Fri Apr 7 18:18:29 UTC 2017


I think I’m starting to make sense of these damned transformation morphs, though it’s a bit confusing in some areas.

> On 06-04-2017, at 7:43 PM, Bob Arning <arning315 at comcast.net> wrote:
>     | secondHand flex pos elapsed start rads |
>     
>     pos _ 100 at 100.
>     secondHand _ (StringMorph contents: 'seconds') color: Color magenta.
>     flex _ TransformationMorph new.
>     flex addMorph: secondHand.
>     secondHand position: 0 at 0.
>     flex position: pos.
>     flex offset: secondHand position.
>     flex openInWorld explore.
>     start _ Time millisecondClockValue.
>     [elapsed _ Time millisecondClockValue - start. elapsed < 60000] whileTrue: [
>         rads _ Float twoPi * (elapsed \\ 60000) / 60000.
>         flex angle: rads negated.
>         World displayWorldSafely.

This is much more like it. No strange intermediate morphs masquerading as our friend. It’s as if it all makes sense. Briefly, at least, whilst the drugs keep their hold.

If we change to 
   | secondHand flex pos |
    
    pos := 500 at 200.
    secondHand := (RectangleMorph new extent: 10 at 100) color: Color red.
    flex := TransformationMorph new.
    flex addMorph: secondHand.
    secondHand position: -5@ -100. “<— set the bottom centre to be at the parent’s 0 at 0"
    flex position: pos.
    "flex offset: 0 at 0. <— don’t seem to need this"
    flex openInWorld explore.
    start := Time millisecondClockValue.
    [elapsed := Time millisecondClockValue - start. elapsed < 60000] whileTrue: [
        rads := Float twoPi * (elapsed \\ 60000) / 60000.
        flex angle: rads negated.
        World displayWorldSafely.
		(Delay forMilliseconds: 100) wait
    ]
… then we get a nice chubby needle rotating about the middle of its bottom edge, which is a typical want if we have a simple morph-drawn needle. There does seem to be some odd behaviour when one changes the offset and rotates things; the bounds can end up moving in not-yet obvious ways and then things get confusing.

Fiddling with the `secondHand position: ` seems to work ok as a way to choose any point as  the pivot, which is what we’d need for an image of an ornate needle we want to use. Like this one - http://www.cjhclocks.com/images/uploads/large/barometer_silver-face_404.jpg

Of course, one of the next tricks is to find someone with the ‘shoop skills to take an image like that and separate out the needle and dial face as separate images.

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Strange OpCodes: RDL: Rotate Disk Left




More information about the Squeak-dev mailing list