home *** CD-ROM | disk | FTP | other *** search
- property pGraph : {dX:10, minY:0, maxY:200, graphRect:{L:0, t:0, b:200, r:600}, yScaleFactor:0} --bAutoScaleY:true
-
- --to play, uncomment this
- (* tell application "PsyScript"
- activate
- begin experiment
- my updateScaleFactor()
- my graph({10, 20, 30, 40, 50, 60, 20, 100, 200, 201, 50, 50, 50, 50, 50, 50, 50, 50, 50, 20, 100})
- do trial ""
- end experiment
- end tell *)
-
- to graph(theList)
- my updateScaleFactor()
- tell application "PsyScript"
- set myl to L of graphRect of pGraph
- set myt to t of graphRect of pGraph
- set myr to r of graphRect of pGraph
- set myb to b of graphRect of pGraph
- draw poly {{myl, myt}, {myr, myt}, {myr, myb}, {myl, myb}} with closing without filling
- set lastPoint to {(L of graphRect of pGraph), (t of graphRect of pGraph)}
- set n to 0
- set listCount to count of theList
- (* if bAutoScaleY then
-
- end if *)
- repeat with xPixel from (L of graphRect of pGraph) to (r of graphRect of pGraph) by (dX of pGraph)
- set n to n + 1
- if n > listCount then
- exit repeat
- else
- set yValue to item n of theList
- (* if bAutoScaleY then
-
- else *)
- if (yValue > maxY of pGraph) then
- set yValue to maxY of pGraph
- else if (yValue < minY of pGraph) then
- set yValue to maxY of pGraph
- end if
- set yPixel to yValue * (yScaleFactor of pGraph) + (b of graphRect of pGraph)
- set newPoint to {xPixel, yPixel}
- draw line from lastPoint to newPoint
- set lastPoint to newPoint
- end if
- set yPixel to yValue * (yScaleFactor of pGraph) + (b of graphRect of pGraph)
- set newPoint to {xPixel, yPixel}
- draw line from lastPoint to newPoint
- set lastPoint to newPoint
-
- --coudl make it that if dX is negative, then fill the width of graphRect
- (* end if *)
- end repeat
- end tell
- end graph
-
- to updateScaleFactor() --check the scale factor
- set t to t of graphRect of pGraph
- set b to b of graphRect of pGraph
- set maxY to maxY of pGraph
- set minY to minY of pGraph
- set yScaleFactor of pGraph to (t - b) / ((maxY) - (minY))
- end updateScaleFactor