Hashengine-2.3/HEMD.py

119 lines
2.8 KiB
Python

import threading
from decimal import localcontext, Decimal, ROUND_HALF_UP
class color3:
def __init__(self, r=0, g=0, b=0):
self.r = r
self.g = g
self.b = b
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
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):
return self._add(v)
def __sub__(self, v):
return self._sub(v)
def __mul__(self, v):
return self._mul(v)
def __iadd__(self, v):
return self._add(v)
def __isub__(self, v):
return self._sub(v)
def __imul__(self, v):
return self._mul(v)
class vector2:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def __copy__(self):
return vector2(self.x, self.y)
def __tround__(self, target):
with localcontext() as ctx:
ctx.rounding = ROUND_HALF_UP
return Decimal(target).to_integral_value()
def __round__(self):
return vector2(self.__tround__(self.x), self.__tround__(self.y))
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)