[Newbies] Quick noob snippets
Karl Ramberg
karlramberg at gmail.com
Tue May 20 15:26:28 UTC 2008
Bert Freudenberg wrote:
>
> On 20.05.2008, at 16:46, Karl Ramberg wrote:
>
>> Bert Freudenberg wrote:
>>>
>>> On 20.05.2008, at 07:01, Herbert König wrote:
>>>
>>>> Hello Sven,
>>>>
>>>> don't know about your first Question though people now may think it
>>>> has been replied to.
>>>>
>>>>
>>>> SS> 100 timesRepeat: [randomNo := 100 atRandom. anEllipse height:
>>>> SS> randomNo. anEllipse borderWidth: anEllipse borderWidth + 1 ]
>>>>
>>>> SS>
>>>> SS> It did work but it did the moves all at once. At first I
>>>>
>>>> World doOneCycleNow
>>>> will update the UI and
>>>> (Delay forMilliseconds: 20) wait
>>>> will give you some time to watch every step.
>>>>
>>>> So your loop might look like
>>>>
>>>> 100 timesRepeat: [randomNo := 100 atRandom.
>>>> anEllipse height: randomNo.
>>>> anEllipse borderWidth: anEllipse borderWidth + 1.
>>>> World doOneCycleNow.
>>>> (Delay forMilliseconds: 20) wait]
>>>
>>>
>>>
>>> Note that #doOneCycleNow is a Bad Hack, never to be used in real
>>> code, being punished by <insert favorite tim quote>.
>>>
>>> The Right Way to do this in Morphic is to add a #step method in your
>>> own Morph subclass.
>> Then you should have a look at ColorPickerMorph :-)
>
>
> Keep in mind we are on the beginners list. I do know where this is
> used, and why. But if someone asks this on the beginners list it is
> bad advice to give.
Yes, I know. I browsed the color picker code the other day and I thought
it looked kind of unusual.
>
> If you know *exactly* what you are doing, like if you are working on
> the system-level implementation of a modal color picker, or the
> internal logic of an MVC-like pop-up menu that actually has to wait
> until closed before returning a value, then yes, #doOneCycleNow is
> useful. It still is a dangerous hack, because even though it looks
> innocuous, it is actually a recursive call on something that's not
> particularly designed for recursion (in Morphic, you are always in a
> doOneCycle already).
Some of the code in FileList2 is modal, and recurse when you click the
wrong folder :-(
Karl
More information about the Beginners
mailing list