here's the code I have thus far but I'm guessing I'd need to add your sorting method somewhere in this.
Code: Select all
On MouseUp
-- draws a line across the middle of the stack
put "0" &","&trunc(.5 * the height of stack SineWave) & CR into tmp
put the width of this stack &","&trunc(.5 * the height of stack SineWave) after tmp
set the points of grc line1 to tmp
-- end draw line
put empty into plotpoints
put "0" & "," & trunc(.5 * the height of stack SineWave) into startPoint
put trunc(.25 * the height of stack SineWave) into amplitude --changeable
put 1 into hScale --changeable
put 2 into angFreq
put trunc(the width of stack SineWave) into theWidth
put trunc(the height of stack SineWave /2) into theHeight
repeat with y = 0 to trunc(the width of stack SineWave)
put hScale * (y) into xPoint
put trunc(sin(toDegrees(angFreq * y)) * amplitude) + item 2 of startPoint into yPoint
put xPoint & "," & ypoint & CR after plotPoints
if xPoint > theWidth and yPoint > theHeight then exit repeat
end repeat
-- Begin hack to trim line at begining and end
put trunc(.7 * the height of stack SineWave) into tmpVar
put the number of lines of plotPoints into plotNumber
repeat with i = plotNumber down to 0
if (item 2 of line i of plotPoints) < tmpVar then
put i into tmpLine
else
put i into tmpLine
exit repeat
end if
end repeat
delete line tmpLine to plotNumber of plotPoints
put trunc(.7 * the height of stack SineWave) into tmpVar
repeat with i = 0 to the number of lines of plotPoints
if (item 2 of line i of plotPoints )>=tmpVar then
put i into tmpLine
exit repeat
end if
end repeat
delete line 0 to tmpLine of plotPoints
-- end trim line process
set the points of grc curve1 to plotPoints
set the loc of grc curve1 to .5 * theWidth,theHeight
end MouseUp
function toDegrees radians
return sin(radians * pi / 180)
end toDegrees