-
Notifications
You must be signed in to change notification settings - Fork 0
/
produce.py
267 lines (216 loc) · 8.63 KB
/
produce.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
#!/usr/bin/env python
# coding=utf-8
from os.path import expanduser
from shutil import copy
file_name = 'test.ini'
red = 1
green = 1
blue = 1
brightness = 100
horizontal_strip_led_count = 37
vertical_strip_led_count = 24
real_screen_size_x, real_screen_size_y = 2560, 1600
dominant_vertical_strip = True
change_aspect_ratio = False
desired_aspect_ratio = 2.39 # 2.39/1 (> 1)
def position_correction(stretched_size, original_size):
return int(stretched_size / 2 - original_size / 2)
def single_led_parameters(
led_number_, position_x_, position_y_, capture_size_x_,
capture_size_y_, red_, green_, blue_):
return "[LED_" + str(led_number_) + "]\n" + \
"IsEnabled=true\n" \
"Position=@Point(" + str(position_x_) + " " \
+ str(position_y_) + ")\n" + \
"Size=@Size(" + str(capture_size_x_) + " " \
+ str(capture_size_y_) + ")\n" + \
"CoefRed=" + str(red_) + "\n" + \
"CoefGreen=" + str(green_) + "\n" + \
"CoefBlue=" + str(blue_) + "\n" + \
"\n"
if __name__ == '__main__':
print('Generating profile "' + str(file_name) + '"...')
total_number_of_leds = \
2 * horizontal_strip_led_count + 2 * vertical_strip_led_count
dominant_horizontal_strip = False if dominant_vertical_strip else True
x_corner_correction = 2 if dominant_vertical_strip else 0
y_corner_correction = 2 if dominant_horizontal_strip else 0
if change_aspect_ratio:
screen_aspect_ratio = real_screen_size_x / real_screen_size_y
if desired_aspect_ratio >= screen_aspect_ratio:
screen_size_x = real_screen_size_x
screen_size_y = \
int(round(real_screen_size_x / desired_aspect_ratio, 0))
offset_x = 0
offset_y = int(round((real_screen_size_y - screen_size_y) / 2, 0))
else: # Not working yet
screen_size_x = \
int(round(real_screen_size_y / desired_aspect_ratio, 0))
screen_size_y = real_screen_size_y
offset_x = int(round((real_screen_size_x - screen_size_x) / 2, 0))
offset_y = 0
else:
screen_size_x = real_screen_size_x
screen_size_y = real_screen_size_y
offset_x = 0
offset_y = 0
base_capture_size_x = int(round(screen_size_x / (
horizontal_strip_led_count + x_corner_correction), 0))
base_capture_size_y = int(round(screen_size_y / (
vertical_strip_led_count + y_corner_correction), 0))
overlap_stretch_ratio = 1.5 # 1.5
horizontal_strip_stretch_ratio = 3.6 # 3.6
horizontal_strip_capture_size_x = \
int(overlap_stretch_ratio * base_capture_size_x)
horizontal_strip_capture_size_y = \
int(horizontal_strip_stretch_ratio * base_capture_size_y)
horizontal_strip_x_position_correction = position_correction(
horizontal_strip_capture_size_x, base_capture_size_x)
vertical_strip_stretch_ratio = 5.9 # 5.9
vertical_strip_capture_size_x = \
int(vertical_strip_stretch_ratio * base_capture_size_x)
vertical_strip_capture_size_y = \
int(overlap_stretch_ratio * base_capture_size_y)
vertical_strip_y_position_correction = position_correction(
vertical_strip_capture_size_y, base_capture_size_y)
# Lower by number, not spatially (upper limit in real space)!
vertical_strip_upper_y_limit = \
screen_size_y + offset_y - vertical_strip_capture_size_y
vertical_strip_lower_y_limit = offset_y
horizontal_lower_y_limit = offset_y
copy_to_prismatik_profiles_folder = True
output_file_contents_in_terminal = False
preamble = \
"[General]\n" + \
"LightpackMode=Ambilight\n" + \
"IsBacklightEnabled=true\n" + \
"\n" + \
"[Grab]\n" + \
"Grabber=DDupl\n" + \
"IsAvgColorsEnabled=false\n" + \
"IsSendDataOnlyIfColorsChanges=true\n" + \
"Slowdown=50\n" + \
"LuminosityThreshold=3\n" + \
"IsMinimumLuminosityEnabled=true\n" + \
"IsDX1011GrabberEnabled=false\n" + \
"IsDX9GrabbingEnabled=false\n" + \
"\n" + \
"[MoodLamp]\n" + \
"LiquidMode=false\n" + \
"Color=#00ff00\n" + \
"Speed=50\n" + \
"\n" + \
"[Device]\n" + \
"RefreshDelay=100\n" + \
"Brightness=" + str(brightness) + "\n" + \
"Smooth=100\n" + \
"Gamma=2.004\n" + \
"ColorDepth=128\n" + \
"\n"
file = open(file_name, 'w')
file.write(preamble)
# TOP horizontal strip
start_top = 1
end_top = horizontal_strip_led_count
for overall_led_number in range(start_top, end_top + 1):
position_x = overall_led_number * base_capture_size_x \
- horizontal_strip_x_position_correction
position_y = horizontal_lower_y_limit
file.write(
single_led_parameters(
overall_led_number,
position_x,
position_y,
horizontal_strip_capture_size_x,
horizontal_strip_capture_size_y,
red,
green,
blue
)
)
# (facing front of screen) RIGHT vertical strip
start_right = end_top + 1
end_right = start_right + (vertical_strip_led_count - 1)
right_strip_led_number = 1
for overall_led_number in range(start_right, end_right + 1):
position_x = screen_size_x - vertical_strip_capture_size_x
value = (right_strip_led_number - 1) * base_capture_size_y \
- vertical_strip_y_position_correction + offset_y
if value <= vertical_strip_upper_y_limit:
if value >= vertical_strip_lower_y_limit:
position_y = value
else:
position_y = vertical_strip_lower_y_limit
else:
position_y = vertical_strip_upper_y_limit
file.write(
single_led_parameters(
overall_led_number,
position_x,
position_y,
vertical_strip_capture_size_x,
vertical_strip_capture_size_y,
red,
green,
blue
)
)
right_strip_led_number += 1
# BOTTOM horizontal strip
start_bottom = end_right + 1
end_bottom = start_bottom + (horizontal_strip_led_count - 1)
bottom_strip_led_number = 1
for overall_led_number in range(start_bottom, end_bottom + 1):
position_x = screen_size_x \
- ((bottom_strip_led_number + 1) * base_capture_size_x) \
- horizontal_strip_x_position_correction
position_y = screen_size_y + offset_y - horizontal_strip_capture_size_y
file.write(
single_led_parameters(
overall_led_number,
position_x,
position_y,
horizontal_strip_capture_size_x,
horizontal_strip_capture_size_y,
red,
green,
blue
)
)
bottom_strip_led_number += 1
# (facing front of screen) LEFT vertical strip
start_left = end_bottom + 1
end_left = start_left + (vertical_strip_led_count - 1)
left_strip_led_number = 1
for overall_led_number in range(start_left, end_left + 1):
position_x = 0
y_value = screen_size_y + offset_y \
- (left_strip_led_number * base_capture_size_y) \
- vertical_strip_y_position_correction
position_y = y_value if y_value >= vertical_strip_lower_y_limit \
else vertical_strip_lower_y_limit
file.write(
single_led_parameters(
overall_led_number,
position_x,
position_y,
vertical_strip_capture_size_x,
vertical_strip_capture_size_y,
red,
green,
blue
)
)
left_strip_led_number += 1
file.close()
if end_left != total_number_of_leds:
print("Number of LEDs don't add up at end!")
if output_file_contents_in_terminal:
file = open(file_name, 'r')
print(file.read())
file.close()
if copy_to_prismatik_profiles_folder:
print("Copying profile to Primatik profiles folder...")
copy(file_name,
str(expanduser("~") + '/Prismatik/Profiles/' + file_name))
print("Complete.")