Need trig & LCB help
hh
hh at hyperhh.de
Wed Oct 30 17:34:45 EDT 2019
Greg, I've been away from LCB for a while. When reading the last post
again I remembered an improvement that you could try to use:
The current version computes the pathes with every redraw (onPaint).
This is far too often. We could compute the pathes once (in onCreate)
and then update ONLY when needed (= when one of its params changes).
This will give your widget a lot of time for other things and makes
the OnPaint code shorter.
variable mBCircles as List
variable mBigRad as Number
variable mLilRad as Number
variable mInnerRad as Number
variable mBigX as Number
variable mBigY as Number
variable mBNum as Number
[1] in OnCreate write:
put the number of elements in mData into mBNum
put my width/2 into mBigX
put my height/2 into mBigY
put mBigRad-mLilRad into mInnerRad
updateCirclePaths([mBNum,mInnerRad,mLilRad,mBigX,mBigY])
[2] in OnPaint write:
repeat with tButtonNumber from 1 up to mBNum
fill mBCircles[tButtonNumber] on this canvas
end repeat
[3] This does the job minimal often:
Whenever you change one of its params write also
updateCirclePaths([mBNum,mInnerRad,mLilRad,mBigX,mBigY])
[4] This handler computes already the small circle paths:
-- sets the list mBCircles of regularly placed circle paths,
-- turns clockwise from high noon, is centered at point [cX,cY]
-- pL = [numOfCircles,bigRadius,smallRadius,cX,cY]
handler updateCirclePaths (in pL as List) returns nothing
variable tI as Number
variable tPi as Number
variable tPaths as List
put 2*pi/pL[1] into tPi
put [] into tPts
repeat with tI from 0 up to pL[1]-1
push circle path centered at point \
[pL[4]+pL[2]*sin(tI*tPi), pL[5]-pL[2]*cos(tI*tPi)] \
with radius pL[3] onto tPaths
end repeat
put tPaths into mBCircles
end handler
Hope you'll show us your shining new widget ...
More information about the use-livecode
mailing list