;; Impromptu-extended Logo examples
;; Load and evaluate the turtle-graphics.scm library first
;; Read the comments in that library file for details of the syntax of this implementation
;;;;;;;;;;;;;;
;; music
;;;;;;;;;;;;;;
(tg:make piano (au:make-node "aumu" "dls " "appl"))
(au:connect-node piano 0 *au:output-node* 0)
(au:update-graph)
(play-note (now) piano 60 100 10000)
(tg:to (drunk-diatonic-melody pitch time)
(tg:repeat 16 (play-note time piano pitch (random 50 110) 10000)
(tg:make pitch-center (round (+ pitch (- (* (random) 8) 4))))
(tg:set-pos 15 (* (- pitch-center pitch) 8))
(set! pitch (pc:random (- pitch-center 2) (+ pitch-center 2) '(0 2 4 5 7 9)))
(set! time (+ time 11000))))
(tg:clear-screen)
(drunk-diatonic-melody 60 (now))
;;;;;;;;;;;;;;;;;;;;;
;; voice synthesis
;;;;;;;;;;;;;;;;;;;;;
(define voice1 (au:get-speech-channel))
(define voice2 (au:get-speech-channel))
(au:speak (now) voice1 "hello")
(tg:to (random-choice lst)
(tg:item (+ (random (tg:count lst)) 1) lst))
(tg:make nouns (list "men" "women" "wind" "moon" "forest"))
(tg:make verbs (list "thinks" "runs" "laughs" "plays" "dreams"))
(tg:make adjectives (list "beautiful" "magical" "blue" "silent" "large" "new"))
(tg:make predicates (list "under" "over" "beside" "above" "on" "about"))
(tg:make articles (list "the" "several" "one" "each"))
(tg:to (haiku)
(au:speak (now) voice1 (random-choice verbs))
(au:speak (+ (now) 30000) voice2 (random-choice predicates))
(au:speak (+ (now) 60000) voice1 (random-choice nouns))
(au:speak (+ (now) 110000) voice2 (random-choice articles))
(au:speak (+ (now) 140000) voice1 (random-choice adjectives))
(au:speak (+ (now) 170000) voice2 (random-choice nouns))
(au:speak (+ (now) 210000) voice1 (random-choice verbs))
(au:speak (+ (now) 240000) voice2 (random-choice predicates))
(au:speak (+ (now) 270000) voice1 (random-choice adjectives))
(au:speak (+ (now) 300000) voice2 (random-choice nouns)))
(haiku)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; drawing with images
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Have a small image, about 160 pixels square,ready to use for this example
;; Replace the file path in the code with the absolute path to your image.
(tg:set-bg 1 1 1 1)
(tg:clear-screen)
(define image (gfx:load-image "/Users/browna/Desktop/Leaves.png"))
(gfx:set-image-size image 160 120)
(tg:to (image-circle :size)
(tg:pen-up)
(tg:set-pos -260 -100)
(tg:repeat 12
(gfx:draw-image (now) canvas image 0.5 (list (tg:first position) (tg:but-first position)))
(tg:forward :size)
(tg:right 30)))
(tg:clear-screen)
(image-circle 100)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; temporal recursion - Braitenberg Vehicle
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(tg:clear-screen)
(tg:pen-down)
(tg:make go #t)
(tg:to (drive :speed)
(tg:forward 6)
(tg:set-pc (random) (random) (random) 1)
(if (> (tg:get-x) 300) (tg:left (/ (- (tg:get-x) 300) 55)) (tg:right (/ (- (tg:get-x) 300) 35)))
(if (> (tg:get-y) 300) (tg:left (/ (- (tg:get-y) 300) 30)) (tg:right (/ (- (tg:get-y) 300) 46)))
(if go (callback (+ (now) (- *second* (* 500 :speed))) 'drive :speed)))
;; start - evaluate (tg:to (drive.. first.
(tg:clear-screen)
(tg:make go #t)
(drive 80) ;; 100 kph speed limit
;; end by changing the go flag
(tg:make go #f)