-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py~
executable file
·295 lines (229 loc) · 6.96 KB
/
main.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
Main test (Emvivre)
Inspired from Empty Laser (Sam Neurohack)
LICENCE : CC
'''
import pygame
import math
import random
import itertools
import sys
import os
import thread
import time
import frame
import renderer
import dac
from globalVars import *
import gstt
def dac_thread():
while True:
try:
d = dac.DAC(dac.find_first_dac())
d.play_stream(laser)
except Exception as e:
import sys, traceback
print '\n---------------------'
print 'Exception: %s' % e
print '- - - - - - - - - - -'
traceback.print_tb(sys.exc_info()[2])
print "\n"
pass
def DrawTestPattern(f):
l,h = screen_size
L_SLOPE = 30
f.Line((0, 0), (l, 0), 0xFFFFFF)
f.LineTo((l, h), 0xFFFFFF)
f.LineTo((0, h), 0xFFFFFF)
f.LineTo((0, 0), 0xFFFFFF)
f.LineTo((2*L_SLOPE, h), 0)
for i in xrange(1,7):
c = (0xFF0000 if i & 1 else 0) | (0xFF00 if i & 2 else 0) | (0xFF if i & 4 else 0)
f.LineTo(((2 * i + 1) * L_SLOPE, 0), c)
f.LineTo(((2 * i + 2) * L_SLOPE, h), c)
f.Line((l*.5, h*.5), (l*.75, -h*.5), 0xFF00FF)
f.LineTo((l*1.5, h*.5), 0xFF00FF)
f.LineTo((l*.75, h*1.5), 0xFF00FF)
f.LineTo((l*.5, h*.5), 0xFF00FF)
def Align(f):
l,h = screen_size
L_SLOPE = 30
f.Line((0, 0), (l, 0), 0xFFFFFF)
f.LineTo((l, h), 0xFFFFFF)
f.LineTo((0, h), 0xFFFFFF)
f.LineTo((0, 0), 0xFFFFFF)
laser = renderer.LaserRenderer(fwork_holder, gstt.centerx, gstt.centery, gstt.zoomx, gstt.zoomy, gstt.sizex, gstt.sizey)
print str(gstt.centerx) + "," + str(gstt.centery) + "," + str(gstt.zoomx) + "," + str(gstt.zoomy) + "," + str(gstt.sizex) + "," + str(gstt.sizey)
app_path = os.path.dirname(os.path.realpath(__file__))
pygame.init()
screen = pygame.display.set_mode(screen_size)
pygame.display.set_caption("Empty Laser")
clock = pygame.time.Clock()
gstt.centerx = LASER_CENTER_X
gstt.centery = LASER_CENTER_Y
gstt.zoomx = LASER_ZOOM_X
gstt.zoomy = LASER_ZOOM_Y
gstt.sizex = LASER_SIZE_X
gstt.sizey = LASER_SIZE_Y
gstt.finangle = LASER_ANGLE
fwork_holder = frame.FrameHolder()
laser = renderer.LaserRenderer(fwork_holder, gstt.centerx, gstt.centery, gstt.zoomx, gstt.zoomy, gstt.sizex, gstt.sizey)
thread.start_new_thread(dac_thread, ())
update_screen = False
keystates = pygame.key.get_pressed()
(SCREEN_W, SCREEN_H) = screen_size
def draw_circle():
dots = []
PI = math.pi
amp = 200
nb_point = 12
for t in range(0, nb_point+1):
y = (SCREEN_H/2) - amp*math.sin(2*PI*(float(t)/float(nb_point)))
x = (SCREEN_W/2) - amp*math.cos(2*PI*(float(t)/float(nb_point)))
dots.append((int(x),int(y)))
return dots
def draw_hour(p):
amp=100
PI=math.pi
x = (SCREEN_W/2) - amp*math.cos(2*PI*(p/12.))
y = (SCREEN_H/2) - amp*math.sin(2*PI*(p/12.))
dots = [(SCREEN_W/2, SCREEN_H/2), (x, y)]
return dots
def draw_minute(p):
amp=180
PI=math.pi
x = (SCREEN_W/2) - amp*math.cos(2*PI*(p/60.))
y = (SCREEN_H/2) - amp*math.sin(2*PI*(p/60.))
dots = [(SCREEN_W/2, SCREEN_H/2), (x, y)]
return dots
tick = 0
hour_i = 0
minute_i = 0
def draw_sine(f):
dots = []
PI = math.pi
amp = 200
nb_point = 24
for t in range(0, nb_point+1):
y = (SCREEN_H/2) - amp*math.sin(2*PI*(float(t)/float(nb_point)))
x = (SCREEN_W/2) - amp*math.cos(2*PI*f*(float(t)/float(nb_point)))
dots.append((int(x),int(y)))
return dots
f_sine = 0
################
def draw_laser_panel(tick):
dots = []
PI = math.pi
amp = 200
nb_point = 24
for t in range(0, nb_point+1):
if t % 2 == 0:
amp = 180 * abs(math.sin((float(tick)/100)))
else:
amp = 120 * abs(math.sin((float(tick)/100)))
y = (SCREEN_H/2) - amp*math.sin(2*PI*(float(t)/float(nb_point)))
x = (SCREEN_W/2) - amp*math.cos(2*PI*(float(t)/float(nb_point)))
dots.append((int(x),int(y)))
dots.append((int(SCREEN_W/2),int(SCREEN_H/2)))
return dots
game_state = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
break
keystates_prev = keystates[:]
keystates = pygame.key.get_pressed()[:]
if keystates[pygame.K_ESCAPE]:
break
###############################
# THINKING PHASE
# lines_to_display = [(0,0), (SCREEN_W,0), (SCREEN_W-1, SCREEN_H-1), (0,SCREEN_H-1), (0,0)]
#n = 3
#lines_to_display = [(0,0), (SCREEN_W/n,0), (SCREEN_W/n-1, SCREEN_H/n-1), (0,SCREEN_H/n-1), (0,0)]
###############################
screen.fill(0)
fwork = frame.Frame()
# Alignement Case
if keystates[pygame.K_p]:
DrawTestPattern(fwork)
if keystates[pygame.K_x]:
Align(fwork)
if keystates[pygame.K_r]:
gstt.centerx += 20
Align(fwork)
if keystates[pygame.K_t]:
gstt.centerx -= 20
Align(fwork)
if keystates[pygame.K_y]:
gstt.centery += 20
Align(fwork)
if keystates[pygame.K_u]:
gstt.centery -= 20
Align(fwork)
if keystates[pygame.K_f]:
gstt.zoomx += 0.1
Align(fwork)
if keystates[pygame.K_g]:
gstt.zoomx -= 0.1
Align(fwork)
if keystates[pygame.K_h]:
gstt.zoomy += 0.1
Align(fwork)
if keystates[pygame.K_j]:
gstt.zoomy -= 0.1
Align(fwork)
if keystates[pygame.K_c]:
gstt.sizex -= 50
Align(fwork)
if keystates[pygame.K_v]:
gstt.sizex += 50
Align(fwork)
if keystates[pygame.K_b]:
gstt.sizey -= 50
Align(fwork)
if keystates[pygame.K_n]:
gstt.sizey += 50
Align(fwork)
if keystates[pygame.K_l]:
gstt.finangle -= 0.001
Align(fwork)
if keystates[pygame.K_m]:
gstt.finangle += 0.001
Align(fwork)
###############################
# DRAWING PHASE
tick += 1
# cloc
if game_state == 0:
fwork.PolyLineOneColor(draw_circle(), c=0xFF0000 )
fwork.PolyLineOneColor(draw_hour(hour_i), c=0xFFFFFF )
fwork.PolyLineOneColor(draw_minute(minute_i), c=0x00FFFF )
minute_i += 1
if tick % 60 == 0:
hour_i += 1
if tick > 60*5:
game_state += 1
# lissajou
if game_state == 1:
fwork.PolyLineOneColor( draw_sine(f_sine), c=0xFF0000 )
if f_sine > 24:
f_sine = 0
game_state += 1
f_sine += 0.01
if game_state == 2:
fwork.PolyLineOneColor(draw_laser_panel(tick), c=0x00FF00)
if game_state == 3:
pass
###############################
fwork_holder.f = fwork
if update_screen:
update_screen = False
fwork.RenderScreen(screen)
pygame.display.flip()
else:
update_screen = True
clock.tick(100)
pygame.quit()