home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2001 October / macformat-108.iso / Shareware / Math scientific / PsyScript / libraries / graph.lib / graph.lib.rsrc / TEXT_2000_Source Text.txt < prev    next >
Encoding:
Text File  |  2001-05-18  |  2.0 KB  |  63 lines

  1. property pGraph : {dX:10, minY:0, maxY:200, graphRect:{L:0, t:0, b:200, r:600}, yScaleFactor:0} --bAutoScaleY:true
  2.  
  3. --to play, uncomment this
  4. (* tell application "PsyScript"
  5.     activate
  6.     begin experiment
  7.     my updateScaleFactor()
  8.     my graph({10, 20, 30, 40, 50, 60, 20, 100, 200, 201, 50, 50, 50, 50, 50, 50, 50, 50, 50, 20, 100})
  9.     do trial ""
  10.     end experiment
  11. end tell *)
  12.  
  13. to graph(theList)
  14.     my updateScaleFactor()
  15.     tell application "PsyScript"
  16.         set myl to L of graphRect of pGraph
  17.         set myt to t of graphRect of pGraph
  18.         set myr to r of graphRect of pGraph
  19.         set myb to b of graphRect of pGraph
  20.         draw poly {{myl, myt}, {myr, myt}, {myr, myb}, {myl, myb}} with closing without filling
  21.         set lastPoint to {(L of graphRect of pGraph), (t of graphRect of pGraph)}
  22.         set n to 0
  23.         set listCount to count of theList
  24.         (* if bAutoScaleY then
  25.             
  26.         end if *)
  27.         repeat with xPixel from (L of graphRect of pGraph) to (r of graphRect of pGraph) by (dX of pGraph)
  28.             set n to n + 1
  29.             if n > listCount then
  30.                 exit repeat
  31.             else
  32.                 set yValue to item n of theList
  33.                 (*     if bAutoScaleY then
  34.                     
  35.                 else *)
  36.                 if (yValue > maxY of pGraph) then
  37.                     set yValue to maxY of pGraph
  38.                 else if (yValue < minY of pGraph) then
  39.                     set yValue to maxY of pGraph
  40.                 end if
  41.                 set yPixel to yValue * (yScaleFactor of pGraph) + (b of graphRect of pGraph)
  42.                 set newPoint to {xPixel, yPixel}
  43.                 draw line from lastPoint to newPoint
  44.                 set lastPoint to newPoint
  45.             end if
  46.             set yPixel to yValue * (yScaleFactor of pGraph) + (b of graphRect of pGraph)
  47.             set newPoint to {xPixel, yPixel}
  48.             draw line from lastPoint to newPoint
  49.             set lastPoint to newPoint
  50.             
  51.             --coudl make it that if dX is negative, then fill the width of graphRect
  52.             (*     end if *)
  53.         end repeat
  54.     end tell
  55. end graph
  56.  
  57. to updateScaleFactor() --check the scale factor
  58.     set t to t of graphRect of pGraph
  59.     set b to b of graphRect of pGraph
  60.     set maxY to maxY of pGraph
  61.     set minY to minY of pGraph
  62.     set yScaleFactor of pGraph to (t - b) / ((maxY) - (minY))
  63. end updateScaleFactor