global [ last-left-class last-right-class]
to tower-of-love
loop [
setlast-left-class 0
setlast-right-class 0
wait-for-stability
if is-splitsville?
[splitsville]
if are-friends-4-eva?
[friends-4-eva]
if is-true-love?
[true-love]
]
end
to wait-for-stability
; top type last-left-class
; bottom print last-right-class
if (or (or (last-left-class = 0)
(last-right-class = 0))
(or (not (last-left-class = classify left-sensor))
(not (last-right-class = classify right-sensor))))
[ setlast-left-class (classify left-sensor)
setlast-right-class (classify right-sensor)
wait 5 wait-for-stability]
end
to is-splitsville?
output
and (
or ((classify left-sensor) = 2)
((classify right-sensor) = 2))
(and ((classify left-sensor) > 1)
((classify right-sensor) > 1))
end
to are-friends-4-eva?
output
and (
or ((classify left-sensor) = 3)
((classify right-sensor) = 3))
(and ((classify left-sensor) > 2)
((classify right-sensor) > 2))
end
to is-true-love?
output
and ((classify left-sensor) = 4)
((classify right-sensor) = 4)
end
;; Classify takes a pressure sensor reading
;; and returns a number indicating
;; its classification:
;; Result = 1 means below threshold
;; Result = 2 means barely readable
;; Result = 3 means medium readable
;; Result = 4 means strongly readable
to classify :reading
ifelse (:reading < 65)
[output 1]
[ifelse (:reading < 80)
[output 2]
[ifelse (:reading < 120)
[output 3]
[output 4]]]
end
to left-sensor
output sensor 0
end
to right-sensor
output sensor 1
end
to song-1
note 55 4 note 50 5 note 40 15
end
to song-3
note 80 2 note 80 2 note 83 4
note 80 1 note 85 1 note 90 1
note 95 1 note 100 4
end
to song-2
note 75 3 note 90 2 note 95 3
note 60 10
end
to curtain-up
b, thisway onfor 5
end
to curtain-down
b, thatway onfor 4
end
to splitsville
a, thatway onfor 35
song-1
wait 15
a, thisway onfor 35
end
to friends-4-eva
a, thatway onfor 50
song-2
wait 15
a, thisway onfor 50
end
to true-love
a, thatway onfor 75
song-3
curtain-up
wait 760
curtain-down
a, thisway onfor 75
end
Cricket code: Love Bug show
to do-show
loop[
wait 15
if sensora > 80 [
forward
dance
wait 195
backup
]]
end
to forward
ab, thisway onfor 50
end
to backup
ab, thatway onfor 50
end
to dance
swing
cha-cha
swing
cha-cha
swing
cha-cha
swing
cha-cha
swing
cha-cha
swing
cha-cha
swing
cha-cha
swing
cha-cha
swing
end
to swing
repeat 4 [ side-to-side]
ab, off
end
to side-to-side
b, thatway onfor 5
a, thisway onfor 5
end
to cha-cha
repeat 3 [back-and-forth]
ab, off
end
to back-and-forth
ab, thisway onfor 2
ab, thatway onfor 2
end
Cricket Code: Music Bug
to music-bug
loop [
wait 15
if sensora > 70
[forward-1
wait 5
backup-1
wait 455
forward-2
wait 5
backup-2
]]
end
to forward-1
ab, thisway onfor 70
end
to backup-1
ab, thatway onfor 65
end
to forward-2
ab, thisway onfor 65
end
to backup-2
ab, thatway onfor 70
end