93 lines
3.2 KiB
Python
93 lines
3.2 KiB
Python
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 move(self, delta, duration):
|
|
self.add_task(group = "move", start_time = Aux.gettime(), duration = duration, delta = delta)
|
|
def update(self):
|
|
for i in self.tasks.get("move", []):
|
|
self.teleport(Aux.tuple_scale(tup = i['delta'], mul = Aux.getprogress(i)))
|
|
def render(self):
|
|
pygame.draw.aaline(self.attached_frame.surface, self.color, Aux.pixelizer(self.ends[0], self.attached_window), Aux.pixelizer(self.ends[1], self.attached_window))
|
|
class Rect(Element):
|
|
def __init__(self, nw_posc=(0.1, 0.1), se_posc=(0.2,0.2), color = "#114514", width = 0): # non-0 for "frame"
|
|
self.color = color
|
|
self.width = width
|
|
self.rect = (nw_posc[0], nw_posc[1], se_posc[0], se_posc[1])
|
|
def move(self, delta, duration):
|
|
self.add_task(group = "move", start_time = Aux.gettime(), duration = duration, delta = delta)
|
|
def update(self):
|
|
for i in self.tasks.get("move", []):
|
|
self.teleport(Aux.tuple_scale(tup = i['delta'], mul = Aux.getprogress(i)))
|
|
def render(self):
|
|
pygame.draw.rect(surface=self.attached_frame.surface, color=self.color, rect=Aux.pixelizer(self.rect, self.attached_window), width=self.width)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Graph:
|
|
@staticmethod
|
|
def rect(frame, pos: tuple = (0, 0), size: tuple = (1, 1), color: tuple = (255, 255, 255), width: int = 0):
|
|
pygame.draw.rect(frame.surface, color=color, rect=(pos[0], pos[1], size[0], size[1]), width=width)
|
|
|
|
@staticmethod
|
|
def line(frame, start_pos: tuple, end_pos: tuple, color: tuple = (255, 255, 255)):
|
|
pygame.draw.aaline(frame.surface, color, start_pos, end_pos)
|
|
|
|
@staticmethod
|
|
def circle(frame, center: tuple, radius: int, color: tuple = (255, 255, 255), width: int = 0):
|
|
pygame.draw.circle(frame.surface, color, center, radius, width)
|
|
|
|
@staticmethod
|
|
def ellipse(frame, pos: tuple = (0, 0), size: tuple = (1, 1), color: tuple = (255, 255, 255), width: int = 0):
|
|
rect=(pos[0], pos[1], size[0], size[1])
|
|
pygame.draw.ellipse(frame.surface, color, rect, width)
|
|
|
|
@staticmethod
|
|
def polygon(frame, pointlist: list, color: tuple = (255, 255, 255), width: int = 0):
|
|
pygame.draw.polygon(frame.surface, color, pointlist, width)
|
|
|
|
@staticmethod
|
|
def arc(frame, pos: tuple = (0, 0), size: tuple = (1, 1), color: tuple = (255, 255, 255), start_angle: float = 0, stop_angle: float = 3.14, width: int = 1):
|
|
rect=(pos[0], pos[1], size[0], size[1])
|
|
pygame.draw.arc(frame.surface, color, rect, start_angle, stop_angle, width)
|
|
|
|
@staticmethod
|
|
def point(frame, pos: tuple, color: tuple = (255, 255, 255)):
|
|
pygame.draw.point(frame.surface, color, pos)
|
|
|
|
@staticmethod
|
|
def lines(frame, pointlist: list, color: tuple = (255, 255, 255)):
|
|
pygame.draw.aalines(frame.surface, color, closed=False, points=pointlist)
|
|
|
|
@staticmethod
|
|
def call(frame, method, **kwargs):
|
|
if hasattr(Graph, method):
|
|
getattr(Graph, method)(frame, **kwargs)
|
|
else:
|
|
print(f"方法 {method} 不存在") |