forked from Hack-a-Day/Vectorscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanets.py
145 lines (119 loc) · 3.66 KB
/
planets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# A little slideshow you can customize
## Images need to be in true color / jpg
## Example conversion: convert Death_Star.jpg -resize 240x240 -type TrueColor thats_no_moon.jpg
import screennorm
import keyboardcb
import keyleds
import vectoros
import timer
import gc
import asyncio
from vos_state import vos_state
import colors
screen=screennorm.ScreenNorm() # get the screen
current_slide=0 # current slide
exit_flag=False # don't exit
tid=None # timer ID
timer_rate=100 # timer rate (ticks; see vos_launch.py for multiplier)
pauseflag=False # pause slide show
# comamnds for slides
TEXT=0
IMAGE=1
BACKGROUND=2
TEXTXY=3
slides=[
[ IMAGE, "pl_mercury.jpg" ],
[ IMAGE, "pl_venus.jpg" ],
[ IMAGE, "pl_earth.jpg" ],
[ IMAGE, "pl_moon.jpg" ],
[ IMAGE, "pl_mars.jpg" ],
[ IMAGE, "pl_jupiter.jpg" ],
[ IMAGE, "pl_saturn.jpg" ],
[ IMAGE, "pl_uranus.jpg" ],
[ IMAGE, "pl_neptune.jpg" ],
[ IMAGE, "pl_pluto.jpg" ],
[ IMAGE, "pl_thats_no_moon.jpg" ]
]
# get next slide
def next():
global current_slide, TEXT, IMAGE
bkflag=False
if pauseflag:
return # nothing doing
cmdlist=slides[current_slide]
if cmdlist[0]==IMAGE or cmdlist[0]==BACKGROUND:
print(cmdlist[1])
screen.jpg(cmdlist[1])
if cmdlist[0]==BACKGROUND:
bkflag=True
current_slide+=1
if current_slide>=len(slides):
current_slide=0
cmdlist=slides[current_slide] #assume next one will be TEXT
if cmdlist[0]==TEXT:
x=40
y=40
if cmdlist[0]==TEXTXY:
x=cmdlist[1]
y=cmdlist[2]
cmdlist[0]=TEXT
del cmdlist[1:3]
if cmdlist[0]==TEXT:
if bkflag==False:
screen.clear(cmdlist[2])
for txt in cmdlist[3:]:
screen.text(x,y,txt,cmdlist[1], cmdlist[2])
y+=30
current_slide+=1 # advance slide
if current_slide>=len(slides):
current_slide=0 # or recycle
# if you change the timeout we have to kill the old timer and make a new one
def update_timer():
global tid, timer_rate
timer.Timer.remove_timer(tid)
tid=timer.Timer.add_timer(timer_rate,next) # change over
# Joystick
# Up is delay up, Down is delay down
# Right is next, and Left toggles the pause flag
def joycb(key):
global timer_rate, pauseflag
if (key==keyleds.JOY_UP):
timer_rate+=10
if timer_rate>200:
timer_rate=200
update_timer()
if (key==keyleds.JOY_DN):
timer_rate-=10
if timer_rate<=0:
timer_rate=1
update_timer()
if (key==keyleds.JOY_RT):
oldpause=pauseflag
update_timer() # reset auto-advance timer
pauseflag=False # make sure it redraws
next()
pauseflag=oldpause
if (key==keyleds.JOY_LF):
pauseflag=not pauseflag
def menu(key): # menu -bail out
global exit_flag
exit_flag=True
async def vos_main():
global exit_flag, current_slide, tid, timer_rate
current_slide=0
# we treat the joystick like any other key here
keys=keyboardcb.KeyboardCB({keyleds.KEY_MENU: menu, keyleds.JOY_UP: joycb, keyleds.JOY_DN: joycb, keyleds.JOY_RT: joycb, keyleds.JOY_LF: joycb})
tid=timer.Timer.add_timer(timer_rate,next)
# prime it
next()
# do nothing... everything is on keyboard and timer
while exit_flag==False:
await asyncio.sleep_ms(500)
# stop listening for keys
keys.detach()
timer.Timer.remove_timer(tid)
exit_flag=False # next time
vos_state.show_menu=True # tell menu to wake up
if __name__=="__main__":
import vectoros
vectoros.run()