summaryrefslogtreecommitdiff
path: root/examples/statemachine/trafficlight.pystate
diff options
context:
space:
mode:
Diffstat (limited to 'examples/statemachine/trafficlight.pystate')
-rw-r--r--examples/statemachine/trafficlight.pystate37
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/statemachine/trafficlight.pystate b/examples/statemachine/trafficlight.pystate
new file mode 100644
index 0000000..3de7b7f
--- /dev/null
+++ b/examples/statemachine/trafficlight.pystate
@@ -0,0 +1,37 @@
+# define state machine
+statemachine TrafficLight:
+ Red -> Green
+ Green -> Yellow
+ Yellow -> Red
+
+
+# define some class level constants
+Red.carsCanGo = False
+Yellow.carsCanGo = True
+Green.carsCanGo = True
+
+
+# setup some class level methods
+def flashCrosswalk(s):
+ def flash():
+ print("%s...%s...%s" % (s, s, s))
+
+ return flash
+
+
+Red.crossingSignal = staticmethod(flashCrosswalk("WALK"))
+Yellow.crossingSignal = staticmethod(flashCrosswalk("DONT WALK"))
+Green.crossingSignal = staticmethod(flashCrosswalk("DONT WALK"))
+
+
+# setup some instance methods
+def wait(nSeconds):
+ def waitFn(self):
+ print("<wait %d seconds>" % nSeconds)
+
+ return waitFn
+
+
+Red.delay = wait(20)
+Yellow.delay = wait(3)
+Green.delay = wait(15) \ No newline at end of file