2024-07-04 15:23:29 +02:00
|
|
|
import threading
|
2024-07-05 15:27:31 +02:00
|
|
|
from decimal import localcontext, Decimal, ROUND_HALF_UP
|
2024-07-04 15:23:29 +02:00
|
|
|
|
|
|
|
class color3:
|
|
|
|
def __init__(self, r=0, g=0, b=0):
|
|
|
|
self.r = r
|
|
|
|
self.g = g
|
|
|
|
self.b = b
|
|
|
|
|
2024-07-04 20:26:48 +02:00
|
|
|
def __maxnum__(self, target, maxn):
|
|
|
|
return "0"*(maxn-len(target))+target
|
|
|
|
|
|
|
|
def __tohex__(self):
|
|
|
|
r = self.__maxnum__(hex(self.r)[2:], 2)
|
|
|
|
g = self.__maxnum__(hex(self.g)[2:], 2)
|
|
|
|
b = self.__maxnum__(hex(self.b)[2:], 2)
|
|
|
|
return "#"+r+g+b
|
|
|
|
|
2024-07-04 15:23:29 +02:00
|
|
|
def _add(self,v):
|
|
|
|
temp = color3(self.r+v.r, self.g+v.g, self.b+v.b)
|
|
|
|
temp.r = temp.r%255
|
|
|
|
temp.g = temp.g%255
|
|
|
|
temp.b = temp.b%255
|
|
|
|
return temp
|
|
|
|
|
|
|
|
def _sub(self,v):
|
|
|
|
temp = color3(self.r-v.r, self.g-v.g, self.b-v.b)
|
|
|
|
temp.r = temp.r%255
|
|
|
|
temp.g = temp.g%255
|
|
|
|
temp.b = temp.b%255
|
|
|
|
return temp
|
|
|
|
|
|
|
|
def _mul(self,v):
|
|
|
|
temp = color3(self.r*v.r, self.g*v.g, self.b*v.b)
|
|
|
|
temp.r = temp.r%255
|
|
|
|
temp.g = temp.g%255
|
|
|
|
temp.b = temp.b%255
|
|
|
|
return temp
|
|
|
|
|
|
|
|
def __add__(self, v):
|
2024-07-04 20:26:48 +02:00
|
|
|
return self._add(v)
|
2024-07-04 15:23:29 +02:00
|
|
|
|
|
|
|
def __sub__(self, v):
|
2024-07-04 20:26:48 +02:00
|
|
|
return self._sub(v)
|
2024-07-04 15:23:29 +02:00
|
|
|
|
|
|
|
def __mul__(self, v):
|
2024-07-04 20:26:48 +02:00
|
|
|
return self._mul(v)
|
2024-07-04 15:23:29 +02:00
|
|
|
|
|
|
|
def __iadd__(self, v):
|
2024-07-04 20:26:48 +02:00
|
|
|
return self._add(v)
|
2024-07-04 15:23:29 +02:00
|
|
|
|
|
|
|
def __isub__(self, v):
|
2024-07-04 20:26:48 +02:00
|
|
|
return self._sub(v)
|
2024-07-04 15:23:29 +02:00
|
|
|
|
|
|
|
def __imul__(self, v):
|
2024-07-04 20:26:48 +02:00
|
|
|
return self._mul(v)
|
2024-07-04 15:23:29 +02:00
|
|
|
|
|
|
|
class vector2:
|
|
|
|
def __init__(self, x=0, y=0):
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
|
2024-08-02 19:30:35 +02:00
|
|
|
def __getdiff__(self, target: list, rint=False):
|
|
|
|
length = len(target)
|
|
|
|
added = vector2()
|
|
|
|
for i in target:
|
|
|
|
added += i
|
|
|
|
out = vector2(added.x/length, added.y/length)
|
|
|
|
if rint == True: out = vector2(int(out.x), int(out.y))
|
|
|
|
return out
|
|
|
|
|
2024-07-04 20:26:48 +02:00
|
|
|
def __copy__(self):
|
|
|
|
return vector2(self.x, self.y)
|
|
|
|
|
2024-07-05 15:27:31 +02:00
|
|
|
def __tround__(self, target):
|
|
|
|
with localcontext() as ctx:
|
|
|
|
ctx.rounding = ROUND_HALF_UP
|
|
|
|
return Decimal(target).to_integral_value()
|
|
|
|
|
2024-07-04 15:23:29 +02:00
|
|
|
def __round__(self):
|
2024-07-05 15:27:31 +02:00
|
|
|
return vector2(self.__tround__(self.x), self.__tround__(self.y))
|
2024-07-04 15:23:29 +02:00
|
|
|
|
|
|
|
def __add__(self, v):
|
|
|
|
return vector2(self.x+v.x, self.y+v.y)
|
|
|
|
|
|
|
|
def __sub__(self, v):
|
|
|
|
return vector2(self.x-v.x, self.y-v.y)
|
|
|
|
|
|
|
|
def __mul__(self, v):
|
|
|
|
return vector2(self.x*v.x, self.y*v.y)
|
|
|
|
|
|
|
|
def __iadd__(self, v):
|
|
|
|
return vector2(self.x+v.x, self.y+v.y)
|
|
|
|
|
|
|
|
def __isub__(self, v):
|
|
|
|
return vector2(self.x-v.x, self.y-v.y)
|
|
|
|
|
|
|
|
def __imul__(self, v):
|
|
|
|
return vector2(self.x*v.x, self.y*v.y)
|
|
|
|
|
|
|
|
class NULL:
|
|
|
|
def __init__(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
class enum:
|
|
|
|
def __init__(self, sel):
|
|
|
|
self._sel = dict(sel)
|
|
|
|
for i in self._sel:
|
|
|
|
setattr(self, i, self._sel[i])
|
|
|
|
|
|
|
|
def getposssel(self):
|
|
|
|
return list(self._sel.keys())
|
|
|
|
|
|
|
|
class event:
|
|
|
|
def __init__(self):
|
|
|
|
self._attached = []
|
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
threads = []
|
|
|
|
for i in self._attached:
|
|
|
|
temp = threading.Thread(target=i)
|
|
|
|
temp.start()
|
|
|
|
threads.append(temp)
|
|
|
|
return threads
|
|
|
|
|
|
|
|
def attach(self, target):
|
|
|
|
self._attached.append(target)
|