;;;;SUMMARY ;; An example of a sliding plot ;;;; COPYRIGHT ;; Copyright (C) 2006 James P. Steiner ;; Some Rights Reserved. ;; Licenced under Creative Commons 2.0 by-sa-nc license ;; globals [ tick plot-list opx ] to setup ca set plot-list n-values 200 [ 0 ] cct 1 [ pd set pen-size 2 ] set opx 0 end to sliding-plot [ new-plot-data ] set plot-list lput (new-plot-data) (but-first plot-list) if tick mod 2 = 0 [ clear-plot foreach plot-list [ plot ? ] ] end to normal-plot [ new-plot-data ] plot new-plot-data end to demo no-display let new-plot-data random-float 2 + (10 * sin tick * cos (tick * 2) ) ask turtle 0 [ set color timer setxy (xcor + .2) new-plot-data if xcor >= screen-edge-x [ pu set xcor (- screen-edge-x)] ; max-pxcor [ pu ] if xcor <= (- screen-edge-x) [ pd ] ; min-pxcor if opx != pxcor [ ask patches with [ pxcor = pxcor-of myself ] [ set pcolor scale-color color-of myself pycor (- screen-edge-y) new-plot-data ] set opx pxcor ] ] if xcor-of turtle 0 = (- screen-edge-x) [ wait .25 cd ] ifelse sliding-plot? [ sliding-plot new-plot-data ] [ normal-plot new-plot-data ] set tick tick + 1 display end @#$#@#$#@ GRAPHICS-WINDOW 282 45 497 231 20 15 5.0 1 10 1 1 1 0 1 1 1 CC-WINDOW 5 256 506 351 Command Center 0 PLOT 7 57 269 242 plot 1 NIL NIL -5.0 205.0 -15.0 15.0 true false BUTTON 89 12 152 45 NIL demo T 1 T OBSERVER T NIL BUTTON 12 12 75 45 NIL setup NIL 1 T OBSERVER T NIL SWITCH 162 13 283 46 sliding-plot? sliding-plot? 0 1 -1000 @#$#@#$#@ = WHAT IS IT? = A small example of a sliding plot = HOW IT WORKS = It stores the data in a list. The oldest data (the last list item) is removed. The whole plot is cleared, then the whole list is plotted. This produces a sliding plot. = THINGS TO NOTICE = If the plot parameters (min/max x and y ranges) are not set correctly for the data, and auto-plot is on, the plot will blink and jump unattractively. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 @#$#@#$#@ NetLogo 3.0.2 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@