diff --git a/pulsar/main.py b/pulsar/main.py index ac159ec..cbd8b7d 100644 --- a/pulsar/main.py +++ b/pulsar/main.py @@ -9,19 +9,21 @@ def horizontal_indicator(): vgl.elements.Line(ends=[(0.4, 0.5), (0.6, 0.5)], color="green").attach(frame_object=frame) pass -@window.observerize -def observer(info): - if info["delta"] == "key": - print(info) - pass - def marking_lines(): global window frame = vgl.Frame().attach(window_object=window, poscale=(0,0), clone_name="Marking Line") + lines = list() for i in range(0, 24): - vgl.elements.Line(ends=[(0, i/24), (1, i/24)], color="green").attach(frame_object=frame) + lines.append(vgl.elements.Line(ends=[(0, i/24), (1, i/24)], color="green").attach(frame_object=frame)) for i in range(0, 32): - vgl.elements.Line(ends=[(i/32, 0), (i/32, 1)], color="green").attach(frame_object=frame) + lines.append(vgl.elements.Line(ends=[(i/32, 0), (i/32, 1)], color="green").attach(frame_object=frame)) + @window.observerize + def observer(info): + if info["delta"] == "key": + print(info) + for i in lines: + i.set_color('#' + str((info['cursor']['position'][0] + info['cursor']['position'][1]*100 + info['cursor']['position'][0]*10000) % 999999).zfill(6)) + observer() def console(): print("You've entered Pulsar's command console, an embbedded Python interpreter for debugging & testing") @@ -32,14 +34,13 @@ def console(): return exec(i) except: - print("An error caused & captured") + print("An error occured & captured") if __name__ == '__main__': print("Welcome to AiraPulsar Client") window.start() horizontal_indicator() marking_lines() - observer() console() input("任意键以退出") window.kill() diff --git a/vgl/__init__.py b/vgl/__init__.py index 779214e..7391c49 100644 --- a/vgl/__init__.py +++ b/vgl/__init__.py @@ -3,5 +3,5 @@ os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "True" from .main import * from . import basic_elements as elements -version = '0.2.0' +version = '0.3.0' print(f"Powered by Vector Graphic Layer, version {version}") \ No newline at end of file diff --git a/vgl/__pycache__/__init__.cpython-312.pyc b/vgl/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..8168771 Binary files /dev/null and b/vgl/__pycache__/__init__.cpython-312.pyc differ diff --git a/vgl/__pycache__/basic_elements.cpython-312.pyc b/vgl/__pycache__/basic_elements.cpython-312.pyc new file mode 100644 index 0000000..8189ded Binary files /dev/null and b/vgl/__pycache__/basic_elements.cpython-312.pyc differ diff --git a/vgl/__pycache__/main.cpython-312.pyc b/vgl/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..e2649c0 Binary files /dev/null and b/vgl/__pycache__/main.cpython-312.pyc differ diff --git a/vgl/basic_elements.py b/vgl/basic_elements.py index 9693dc9..b4d4a65 100644 --- a/vgl/basic_elements.py +++ b/vgl/basic_elements.py @@ -1,10 +1,13 @@ from vgl.main import * import pygame import time + class Line(Element): def __init__(self, ends = [(0.1, 0.1), (0.2, 0.2)], color = "#ffffff"): self.color = color self.ends = ends + def set_color(self, new_color): + self.color = new_color def move(self, delta, duration): self.add_task(group = "move", start_time = Aux.gettime(), duration = duration, delta = delta) def update(self): diff --git a/vgl/main.py b/vgl/main.py index 52db9cb..7d803c6 100644 --- a/vgl/main.py +++ b/vgl/main.py @@ -87,6 +87,72 @@ class Aux(): #print("不重要事件") return 0 return 1 +class Anchor(object): + """ + "锚定点" 对象 + """ + poscale = (0, 0) + fixed = 3 + def __init__(self, *args): + if isinstance(args[0], tuple) or isinstance(args[0], Anchor): + if isinstance(args[0], Anchor): + self.poscale = args[0].poscale + else: + self.poscale = args[0] + else: + self.poscale = (args[0], args[1]) + def x(self): + return self.poscale[0] + def y(self): + return self.poscale[1] + def __add__(self, other): + if isinstance(other, tuple): + return Anchor((self.poscale[0] + other[0], self.poscale[1] + other[1])) + elif isinstance(other, Anchor): + return Anchor((self.poscale[0] + other.poscale[0], self.poscale[1] + other.poscale[1])) + else: + raise TypeError("不支持的加法操作数类型") + def __mul__(self, other): + "向屏幕中心倍增/倍缩" + if isinstance(other, tuple): + return Anchor((0.5 + other[0] * (self.poscale[0] - 0.5), 0.5 + other[1] * (self.poscale[1] - 0.5))) + elif isinstance(other, (int, float)): + return Anchor((0.5 + other * (self.poscale[0] - 0.5), 0.5 + other * (self.poscale[1] - 0.5))) + else: + raise TypeError("不支持的乘法操作数类型") + def __imul__(self, other): + result = self.__mul__(other) + self.poscale = result.poscale + return self + def __truediv__(self, other): + "乘以倒数" + if isinstance(other, (int, float)): + if other == 0: + return Anchor((0.5, 0.5)) + else: + return self.__mul__(1 / other) + elif isinstance(other, Anchor) or isinstance(other, tuple): + divisor_x = other[0] if isinstance(other, tuple) else other.x() + divisor_y = other[1] if isinstance(other, tuple) else other.y() + # TODO: 错误代码, 应当予以修正 + if divisor_x == 0 and divisor_y == 0: + return Anchor((0.5, 0.5)) + if divisor_x == 0 and divisor_y == 0: + return Anchor((0.5, 0.5)) + else: + return self.__mul__((1 / divisor_x, 1 / divisor_y)) + else: + raise TypeError("不支持的除法操作数类型") + def __itruediv__(self, other): + "就地除法" + result = self.__truediv__(other) + self.poscale = result.poscale + return self + def __str__(self): + if self.fixed is not None: + return f"({round(self.poscale[0], self.fixed)}, {round(self.poscale[1], self.fixed)})" + else: + return f"({self.poscale[0]}, {self.poscale[1]})" class Element(object): is_hide = False is_template = True