-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlight-painting.py
144 lines (124 loc) · 3.45 KB
/
light-painting.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
"""
Light-painting test. Results could be much better
with a proper motor instead of waving my hand in front of the camera.
"""
import microbit
# banner bitmap, exported from gimp to XPM+search/replace
banner = bytearray( "97579"
" 5 "
" 5 "
"95579"
" "
"95579"
"9 5 9"
"9 5 9"
"9 9"
" "
"95579"
"9 "
"9 "
"9 "
" "
"75579"
"7 "
"7 "
"7 "
" "
" 557 "
"9 9"
"9 9"
" 557 "
" "
" "
" "
" "
"99799"
" 7 "
" 5 "
" 7 "
"97579"
" "
"9 9"
"97579"
"9 9"
" "
" 757 "
"9 9"
"9 9"
" 7 7 "
" "
"97579"
" 7 9"
" 7 9"
"9 57 "
" "
" 755 "
"9 9"
"9 9"
" 757 "
" "
" 7 7 "
" "
"97579"
"9 5 9"
"9 5 9"
" 7 5 "
" "
"9 9"
"97559"
"9 9"
" "
" 9"
"97559"
" 9"
" "
" "
"9 559"
" "
" "
" "
" "
" "
" "
" "
" "
" "
" "
" "
" ")
# convert banner values to 0-9
for i, x in enumerate(banner):
if x == ord(" "):
x = 0
else:
x = x - ord("0")
banner[i] = x
# calculate delays
number_of_columns = int(len(banner)/5)
exposure = 4.0 # seconds
frame_wait_ms = int(1000*exposure/number_of_columns)
# image that contains window of the banner
image = microbit.Image(5, 5)
# current banner ptr
banner_ptr = 0
banner_ptr_end = len(banner)
# main loop
while True:
start_frame_ms = microbit.running_time()
# display current banner window
ptr = banner_ptr
for y in range(5):
for x in range(5):
image.set_pixel(y, 4-x, banner[ptr])
ptr += 1
# wrap around
if ptr >= banner_ptr_end:
ptr = 0
# display the image
microbit.display.show(image)
# next banner row
banner_ptr += 5
if banner_ptr >= banner_ptr_end:
banner_ptr = 0
# wait for the next frame
microbit.sleep(frame_wait_ms - (microbit.running_time()-start_frame_ms))