Script demo_FunctionCyclePlan_py
|
|
1 from joy import *
2 from math import sin,pi
3
18
20 if evt.type==KEYDOWN:
21 if evt.key in [ord('q'),27]:
22 self.stop()
23
24 elif evt.key==ord(' '):
25 self.plan.setPeriod(0)
26 progress('Period changed to %s' % str(self.plan.period))
27
28 elif evt.key in (ord(','),ord('.')):
29 f = self.freq
30
31 if evt.key==ord(','):
32 f = (1-self.rate)*f - self.rate*self.limit
33 else:
34 f = (1-self.rate)*f + self.rate*self.limit
35 if abs(f) < 1.0/self.limit:
36 self.plan.setPeriod( 0 )
37 else:
38 self.plan.setPeriod( 1/f )
39 self.freq = f
40 progress('Period changed to %g, %.2f Hz' % (self.plan.period,f))
41
42 elif evt.key==ord('h'):
43 progress( "HELP: ',' to decrease/reverse period; '.' opposite; ' ' stop; 'q' end program; 'h' this help; other keys start Plan" )
44
45 else:
46 progress( "Starting cycles...." )
47 self.plan.start()
48 if evt.type!=TIMEREVENT:
49 JoyApp.onEvent(self,evt)
50
51 if __name__=="__main__":
52 print """
53 Demo of FunctionCyclePlan class
54 -------------------------------
55
56 When any key is pressed, starts a FunctionCyclePlan that prints
57 an ASCII art sine wave under keyboard control.
58
59 h -- help
60 q -- quit
61 , and . -- change rate
62 SPACE -- pause / resume
63 any other key -- start
64
65 The application can be terminated with 'q' or [esc]
66 """
67 import joy
68 joy.DEBUG[:]=[]
69 app=FunctionCyclePlanApp()
70 app.run()
71