1 from joy import *
2
6
8
9 def wayPt1(self):
10 self.app.scr.sensorUpdate(catX=100,catY=100)
11 def wayPt2(self):
12 self.app.scr.sensorUpdate(catX=100,catY=-100)
13 def wayPt3(self):
14 self.app.scr.sensorUpdate(catX=-100,catY=-100)
15 def wayPt4(self):
16 self.app.scr.sensorUpdate(catX=-100,catY=100)
17 CYCLE = {
18 0.0 : wayPt1,
19 0.2 : wayPt2,
20 0.6 : wayPt3,
21 0.8 : wayPt4
22 }
23 self.plan = CyclePlan(self, CYCLE)
24 self.plan.onStart = curry(progress,">>> START")
25 self.plan.onStop = curry(progress,">>> STOP")
26 self.freq = 1.0
27 self.rate = 0.05
28 self.limit = 1/0.45
29
30
32 if evt.type==KEYDOWN:
33 if evt.key in [ord('q'),27]:
34 self.stop()
35
36 elif evt.key==ord(' '):
37 self.plan.setPeriod(0)
38 progress('Period changed to %s' % str(self.plan.period))
39
40 elif evt.key in (ord(','),ord('.')):
41 f = self.freq
42
43 if evt.key==ord(','):
44 f = (1-self.rate)*f - self.rate*self.limit
45 else:
46 f = (1-self.rate)*f + self.rate*self.limit
47 if abs(f) < 1.0/self.limit:
48 self.plan.setPeriod( 0 )
49 else:
50 self.plan.setPeriod( 1/f )
51 self.freq = f
52 progress('Period changed to %g, %.2f Hz' % (self.plan.period,f))
53
54 elif evt.key==ord('h'):
55 progress( "HELP: ',' to decrease/reverse period; '.' opposite; ' ' stop; 'q' end program; 'h' this help; other keys start Plan" )
56
57 else:
58 progress( "Starting cycles...." )
59 self.plan.start()
60 if evt.type!=TIMEREVENT:
61 JoyApp.onEvent(self,evt)
62
63 if __name__=="__main__":
64 print """
65 Demo of SheetPlan class
66 -----------------------
67
68 Use this demo with the demo-plans.sb Scratch project.
69
70 When any key is pressed, starts a SheetPlan making the
71 cat move around a square.
72
73 The application can be terminated with 'q' or [esc]
74 """
75 import joy
76 joy.DEBUG[:]=[]
77 app=CyclePlanApp()
78 app.run()
79