-
Notifications
You must be signed in to change notification settings - Fork 1
/
small_tools.py
313 lines (255 loc) · 9.3 KB
/
small_tools.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
import bpy
import numpy as np
from .ExternalModules.pyrr import Vector3
class QadricBezier:
def __init__(self, p1, c1, p2 , resolution):
f = 1 / (resolution + 1) # increment based on resolution
#n bezier function data
P1 = p1 # start point of bezier curve
P2 = p2 # end point of bezier curve
C1 = c1 # control point of bezier curve
t = f # position of point along bezier curve
#n final list
self.point_list = []
#n Process
for i in range(0,resolution):
x = pow((1 - t), 2) * P1[0] + 2 * (1 - t) * t * C1[0] + pow(t, 2) * P2[0]
y = pow((1 - t), 2) * P1[1] + 2 * (1 - t) * t * C1[1] + pow(t, 2) * P2[1]
self.point_list.append((x, y,0))
t += f
#n return points
def getPoints(self):
return self.point_list
class squareAlongLine:
def __init__(self, p1, r, angle, center):
distance = r
C1 = p1
Rx = C1[0] + (np.cos(np.deg2rad(angle))*distance)
Ry = C1[1] + (np.sin(np.deg2rad(angle))*distance)
radius = np.cos(np.deg2rad(angle))*distance
#n x y
#n point 1
if p1[0] < center[0] and p1[1] < center[1]: #n if point is to the left and down from center
if Rx >= center[0] : # if X reaches or goes beyound the center
dif = center[0] - C1[0] # find difference between the center.x and Point.x
Ry = C1[1] + dif # corner circle center.y = adding difference to Point.y
Rx = center[0] # corner circle center.x = object center.y
radius = dif # cornder circle radius = the difference
elif Ry >= center[1] :
dif = center[1] - C1[1]
Rx = C1[0] + dif
Ry = center[1]
radius = dif
else:pass
#n point 2
elif p1[0] > center[0] and p1[1] < center[1]:
if Rx <= center[0] :
dif = center[0] - C1[0]
Ry = C1[1] - dif
Rx = center[0]
radius = dif
elif Ry >= center[1] :
dif = center[1] - C1[1]
Rx = C1[0] - dif
Ry = center[1]
radius = dif
else:pass
#n point 3
elif p1[0] > center[0] and p1[1] > center[1]:#pass
if Rx <= center[0] :
dif = center[0] - C1[0]
Ry = C1[1] + dif
Rx = center[0]
radius = dif
elif Ry <= center[1] :
dif = center[1] - C1[1]
Rx = C1[0] + dif
Ry = center[1]
radius = dif
else:pass
#n point 4
elif p1[0] < center[0] and p1[1] > center[1]: # pass
if Rx >= center[0] :
dif = center[0] - C1[0]
Ry = C1[1] - dif
Rx = center[0]
radius = dif
elif Ry <= center[1] :
dif = center[1] - C1[1]
Rx = C1[0] - dif
Ry = center[1]
radius = dif
else:pass
else:pass
P1 = (C1[0], Ry, 0)
P2 = (Rx, C1[1], 0)
self.point_list = [
(Rx,Ry,0),
radius
]
def get_points(self):
return self.point_list
class ParametricCircle:
def __init__(self,center, r, resolution,sector=int):
f = 90/resolution
t = f
self.point_list=[]
if sector == 1:
t = 0
x = center[0] + r * np.cos(np.deg2rad(t))
y = center[1] + r * np.sin(np.deg2rad(t))
self.point_list.append((x,y,0))
for i in range(0,resolution):
x = center[0] + r*np.cos(np.deg2rad(t))
y = center[1] + r*np.sin(np.deg2rad(t))
self.point_list.append((x,y,0))
t += f
x = center[0] + r * np.cos(np.deg2rad(90))
y = center[1] + r * np.sin(np.deg2rad(90))
self.point_list.append((x, y, 0))
if sector == 2:
t = 90
x = center[0] + r * np.cos(np.deg2rad(t))
y = center[1] + r * np.sin(np.deg2rad(t))
self.point_list.append((x, y, 0))
t += f
for i in range(0, resolution):
x = center[0] + r * np.cos(np.deg2rad(t))
y = center[1] + r * np.sin(np.deg2rad(t))
self.point_list.append((x, y, 0))
t += f
x = center[0] + r * np.cos(np.deg2rad(180))
y = center[1] + r * np.sin(np.deg2rad(180))
self.point_list.append((x, y, 0))
if sector == 3:
t = 180
x = center[0] + r * np.cos(np.deg2rad(t))
y = center[1] + r * np.sin(np.deg2rad(t))
self.point_list.append((x, y, 0))
t += f
for i in range(0, resolution):
x = center[0] + r * np.cos(np.deg2rad(t))
y = center[1] + r * np.sin(np.deg2rad(t))
self.point_list.append((x, y, 0))
t += f
x = center[0] + r * np.cos(np.deg2rad(270))
y = center[1] + r * np.sin(np.deg2rad(270))
self.point_list.append((x, y, 0))
if sector == 4:
t = 270
x = center[0] + r * np.cos(np.deg2rad(t))
y = center[1] + r * np.sin(np.deg2rad(t))
self.point_list.append((x, y, 0))
t += f
for i in range(0, resolution):
x = center[0] + r * np.cos(np.deg2rad(t))
y = center[1] + r * np.sin(np.deg2rad(t))
self.point_list.append((x, y, 0))
t += f
x = center[0] + r * np.cos(np.deg2rad(360))
y = center[1] + r * np.sin(np.deg2rad(360))
self.point_list.append((x, y, 0))
def getPoints(self):
return self.point_list
class GetThemeColors:
'''
gets some theme colors
'''
def __init__(self):
self.background = None
self.passive = None
self.active = None
current_theme = bpy.context.preferences.themes.items()[0][0]
view_3d = bpy.context.preferences.themes[current_theme].view_3d
user_interface = bpy.context.preferences.themes[current_theme].user_interface.wcol_toolbar_item
self.active = view_3d.object_active
self.active2 = view_3d.object_selected
self.text = user_interface.text
self.passive = view_3d.camera
self.background = user_interface.inner
def getColors(self):
return [self.active,self.active2,self.passive,self.text,self.background]
def remapRange(a, b, c, d, t):
oldNormal = (t-a)/(b-a)
remapedValue = oldNormal*(d-c)+c
if remapedValue < c:
remapedValue = c
elif remapedValue > d:
remapedValue = d
return remapedValue
#n Color Conversion
def rgb_to_hsv(rgb):
# print(f'Inside rgb_to_hsv function\n RGB-in{rgb}\nRGB int {np.array(rgb)*255}')
hue = 0
saturation = 0
value = 0
cMin = np.min(rgb)
cMax = np.max(rgb)
delta = cMax-cMin
# Value
value=cMax
# Saturation Hue
if delta<0.00001:
hue=0
saturation=0
# saturation
if cMax > 0.0:
saturation=(delta/cMax)
else:
saturation=0
hue=0
# hue
if rgb[0] >= cMax: hue = (rgb[1]-rgb[2])/delta
elif rgb[1]>= cMax: hue = 2 + (rgb[2]-rgb[0])/delta
else: hue = 4 + (rgb[0]-rgb[1])/delta
# turn to degrees
hue *= 60
if hue < 0.0: hue += 360
return [hue,saturation,value]
def hsv_to_rgb(h, s, v):
if s == 0.0: return (v, v, v)
i = int(h * 6.) # XXX assume int() truncates!
f = (h * 6.) - i
p, q, t = v * (1. - s), v * (1. - s * f), v * (1. - s * (1. - f))
i %= 6
if i == 0: return (v, t, p)
if i == 1: return (q, v, p)
if i == 2: return (p, v, t)
if i == 3: return (p, q, v)
if i == 4: return (t, p, v)
if i == 5: return (v, p, q)
#n Color harmony - complimentary if I ever need it
def harmonize2rgb(color, harmony):
inHSV = rgb_to_hsv(color)
rHue = inHSV[0]
newHue = 0
outRGB = []
rule = []
if harmony == 'complimentary':
rule = [0,180]
distance = 360-rHue
# print(f'distance {distance}')
if distance > rule[-1]:
newHue = rHue + rule[-1]
else:
newHue = (rHue+rule[-1])-360
# print(f'\n{"":-^20}')
outRGB = hsv_to_rgb(newHue/360,inHSV[1],inHSV[2])
# print(f'In harmonize2rgb\nin RGB{color} HSV{inHSV }\nnew Hue{newHue} , out RGB{outRGB}')
# print(np.array(outRGB)*255)
return outRGB
def rounding_my(number):
init_number = number
return_number = 0
if type(init_number) is type(1):
return init_number
else:
int_number, decimal = str(init_number).split(".")
decimal = float("0." + decimal)
if decimal < .55:
return_number = int(int_number)
else:
return_number = int(int_number) + 1
return return_number
def seconds2frames(seconds, scene_framerate):
return rounding_my(seconds*scene_framerate)