[squeak-dev] Rotating Morphs; how to rotate about a point other than the centre of bounds?
H. Hirzel
hannes.hirzel at gmail.com
Fri Apr 7 19:40:36 UTC 2017
Nice.
But the code blocks the UI for 60 seconds. :-(
--Hannes
On 4/7/17, Bob Arning <arning315 at comcast.net> wrote:
> photoshop is for sissies. use squeak ;-)
>
>
> | secondHand flex pos elapsed rads start fancy bottomHalf smaller |
>
> fancy _ Form extent: 500 at 100 depth: 32.
> fancy fillColor: Color white.
> fancy getCanvas
> fillOval: (5 at 5 extent: 90 at 90) color: Color black;
> fillOval: (0 at 15 extent: 70 at 70) color: Color white;
> fillRectangle: (400 at 20 extent: 60 at 60) color: Color black;
> fillOval: (300@(-348) extent: 400 at 400) color: Color white;
> fillRectangle: (90 at 48 extent: 400 at 4) color: Color black.
> bottomHalf _ fancy copy: (0 at 0 extent: fancy width @ (fancy height
> // 2)).
> bottomHalf flipVertically.
> bottomHalf displayOn: fancy at: 0@(fancy height//2).
> fancy replaceColor: Color white withColor: Color transparent.
>
> pos _ 500 at 200.
> smaller _ fancy magnify: fancy boundingBox by: 0.25 smoothing: 2.
> secondHand _ smaller asMorph.
> flex _ TransformationMorph new.
> flex addMorph: secondHand.
> secondHand position: smaller boundingBox center negated.
> flex position: pos.
> 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
> ]
>
>
> On 4/7/17 2:18 PM, tim Rowledge wrote:
>> 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
|