;;; -*- logo -*-
;; This is offered as part of the sound API.  It's intention is to
;; draw the graph of an array of numbers, presumably corresponding
;; to audio data.
;;
;; copyright University of Victoria, 2004


to followwave :wave :x :delta

;; calculate the next coordinate
make "y (first wave) * 180
make "x (x + delta)
setpos list x y

;; draw recursively until list is empty
test empty? butfirst wave
iffalse [ followwave butfirst wave x delta ]

end


;;
to drawXticks :x

penup
setpos list x -240
pendown

test equal? x -240
iftrue [ setpos list x 240 ]
iffalse [ setpos list x -230 ]
penup

test less? x 240
iftrue [ drawXticks x+48 ]

end

;;
to drawYticks :y

penup
setpos list -240 y
pendown

test equal? y -240
iftrue [ setpos list 240 y ]
iffalse [ setpos list -230 y]
penup

test less? y 240
iftrue [ drawYticks y+48 ]

end

;; each ticks will simply represent 10% of the samples
to drawticks

drawXticks -240
drawYticks -240

end


to drawwave :wave

make "wave arraytolist wave

;; some initializations-- forward 0 is a hack... Penup doesn't seem to
;; work, at least with X Window, until the graphics window has been
;; rendered on screen.  Should be fixed elsewhere.
forward 0 
penup
make "n count wave
make "xposition -240
make "yposition 0
setpos list xposition yposition

;; draw it out using all the points to avoid subsampling aliasing
pendown
hideturtle
followwave wave -240 (480/n)

;; finally add some ticks for reference
drawticks 

end

