Capture the Trig Function from an Option Menu Button
Robert Sneidar
slylabs13 at me.com
Mon Dec 10 17:38:28 EST 2012
Value forces LC to evaluate the expression. Also, you can do something like, "value("the name of me", card 1)". Only other thing I can think of is that "do" compiles a statement at runtime. That means if you have a LOT of do statements running in a loop, there may be a performance hit. Not sure about value though, it might be the same situation.
Bob
On Dec 10, 2012, at 2:11 PM, Jim Hurley wrote:
>
> Thanks Dick. I hadn't thought about using the Value function. Interesting.
> Do you have any thoughts on the relative merits of Do vs. Value?
>
> I could also have used
>
> do "put " & tTrigFunction & "(" & tAngle & ") into y"
>
> And Roger, in my code the positive y axis is the usual screen y axis--positive down.
>
> If you want to use the traditional cartesian y-axis--positive up-- change y0 + y to y0 - y
>
> Otherwise you trig curves will all look upside down.
>
> Jim
>
>
>
>>> On Dec 10, 2012, at 8:59 AM, Jim Hurley wrote:
>>> get "put the " & tTrigFunction & " of " & tAngle & " into y "
>>> do it
>>>
>>>
>>
>> Hi, Jim and Roger.
>>
>> If you like more concise code, you can code the above like this:
>> put value( tTrigFunction & "(" & tAngle & ")" ) into y
>>
>> -- Dick
>>
>>
>> Roger,
>>
>> One caveat. This is a good exampe the caution one must exercise in using the Do.
>>
>> Instead of:
>>
>>>> replace "sine" with "sin" in tTrigFunction
>>>> replace "cosine" with "cos" in tTrigFunction
>>>> replace "tangent" with "tan" in tTrigFunction
>>
>> Use:
>>
>>>> replace "cosine" with "cos" in tTrigFunction
>>
>>>> replace "sine" with "sin" in tTrigFunction
>>>> replace "tangent" with "tan" in tTrigFunction
>>
>> If you replace "sine" with "sin" you also change "cosine" to "cosin" (There is a "sine" in "cosine")
>> So reverse the order of these first two.
>>
>> Jim
>>
>>
>>
>>> ------------------------------
>>>
>>> Message: 3
>>> Date: Mon, 10 Dec 2012 09:42:55 -0800
>>> From: Roger Guay <irog at mac.com>
>>> To: How to use LiveCode <use-livecode at lists.runrev.com>
>>> Subject: Re: Capture the Trig Function from an Option Menu Button
>>> Message-ID: <2F8EAA01-F970-48E0-AF7A-7733AF7E4FB3 at mac.com>
>>> Content-Type: text/plain; CHARSET=US-ASCII
>>>
>>> This script is amazingly fast! And so are you, having apparently produced it in less than an hour!! My script appears to be slightly slower using a switch/case structure. I'll test it out when I get a moment.
>>>
>>> Thanks very much,
>>> Roger
>>>
>>>
>>> On Dec 10, 2012, at 8:59 AM, Jim Hurley <jhurley0305 at sbcglobal.net> wrote:
>>>
>>>> It turns out that Do is fast enough. Here is the Do script:
>>>> (The script might read a litle better by using "x" in the repeat loop instead of "i".)
>>>>
>>>> on mouseUp
>>>> put the label of btn "myOptionMenu" into tTrigFunction
>>>> --It might be necessary to take care in using the following replacements
>>>> replace "sine" with "sin" in tTrigFunction
>>>> replace "cosine" with "cos" in tTrigFunction
>>>> replace "tangent" with "tan" in tTrigFunction
>>>> put round(the width of this card/2) into x0
>>>> put round(the height of this card/2) into y0
>>>> put 50 into Amp--Amplitude of the trig curve
>>>> set the points of grc "myCurve" to empty
>>>> wait 0 millisec -- Force a screen refresh on the Mac
>>>> repeat with i = 1 to 360--maybe with a step of 2 or 4
>>>> put i*pi/180 into tAngle
>>>> get "put the " & tTrigFunction & " of " & tAngle & " into y "
>>>> do it
>>>> put round(Amp*y) into y
>>>> put i into x
>>>> put x+ x0, y+y0 into tPoint
>>>> put tPoint & cr after tPoints
>>>> --Uncomment the following to see the curve evolve
>>>> --set the points of grc "myCurve" to tPoints
>>>> --wait 0 millisec
>>>> end repeat
>>>> set the points of grc "myCurve" to tPoints
>>>> end mouseUp
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> use-livecode at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>>>
>>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list