_
This commit is contained in:
parent
b3c93e804a
commit
125e0e2831
@ -4,8 +4,8 @@ from numpy import array as a
|
||||
|
||||
|
||||
class Scene(Screen):
|
||||
def __init__(self, width: float, height: float, font_size: int, scene_size: a, bg=(60, 60, 60)):
|
||||
super().__init__(width, height, font_size, scene_size)
|
||||
def __init__(self, width: float, height: float, scene_size: a, bg=(60, 60, 60)):
|
||||
super().__init__(width, height, scene_size)
|
||||
|
||||
self.bg = bg
|
||||
self.r_objects = [] # resizable Objects
|
||||
|
@ -4,7 +4,7 @@ import pygame
|
||||
|
||||
|
||||
class Screen:
|
||||
def __init__(self, width: float, height: float, font_size: int, screen_size: a):
|
||||
def __init__(self, width: float, height: float, screen_size: a):
|
||||
pygame.init()
|
||||
|
||||
self.width = width
|
||||
@ -21,9 +21,14 @@ class Screen:
|
||||
self.s_ = pygame.Surface([width, height])
|
||||
self.s = pygame.display.set_mode(screen_size)
|
||||
|
||||
self.font_size = font_size
|
||||
|
||||
self.center = a([width, height]) / 2
|
||||
|
||||
def save(self, path):
|
||||
def save(self, path, size=None):
|
||||
if size is None:
|
||||
pygame.image.save(self.s, path)
|
||||
else:
|
||||
surface = pygame.Surface(size)
|
||||
|
||||
surface.blit(self.s, [0, 0])
|
||||
|
||||
pygame.image.save(surface, path)
|
||||
|
32
UI/Objects/nr_objects/Text.py
Normal file
32
UI/Objects/nr_objects/Text.py
Normal file
@ -0,0 +1,32 @@
|
||||
import pygame
|
||||
|
||||
|
||||
class Text:
|
||||
def __init__(self, position, text, font_size, color, scene, font_name="calibri", bold=True):
|
||||
self.position = position
|
||||
self.text = text
|
||||
self.font_size = font_size
|
||||
self.font_name = font_name
|
||||
self.bold = bold
|
||||
self.color = color
|
||||
self.scene = scene
|
||||
self.scalar = self.scene.matrix[0, 0]
|
||||
|
||||
self.font = pygame.font.SysFont(self.font_name, max(1, int(self.font_size * self.scalar)), self.bold)
|
||||
self.rendered_text = self.font.render(self.text, False, self.color)
|
||||
|
||||
self.blit_position = self.scene.matrix @ self.position
|
||||
self.blit_position[0] -= self.rendered_text.get_width() / 2
|
||||
self.blit_position[1] -= self.rendered_text.get_height() / 2
|
||||
|
||||
def blit(self):
|
||||
if self.scalar != self.scene.matrix[0, 0]:
|
||||
self.scalar = self.scene.matrix[0, 0]
|
||||
self.font = pygame.font.SysFont(self.font_name, max(1, int(self.font_size * self.scalar)), self.bold)
|
||||
self.rendered_text = self.font.render(self.text, False, self.color)
|
||||
|
||||
self.blit_position = self.scene.matrix @ self.position
|
||||
self.blit_position[0] -= self.rendered_text.get_width() / 2
|
||||
self.blit_position[1] -= self.rendered_text.get_height() / 2
|
||||
|
||||
self.scene.s.blit(self.rendered_text, self.blit_position)
|
@ -6,15 +6,16 @@ import numpy as np
|
||||
from UI.Objects.nr_objects.Ellipse import Ellipse
|
||||
from UI.Objects.nr_objects.Circle import Circle
|
||||
from UI.Objects.nr_objects.Line import Line
|
||||
from UI.Objects.nr_objects.Text import Text
|
||||
from UI.Objects.r_objects.Rect import Rect
|
||||
|
||||
|
||||
class BasicScene(Scene):
|
||||
def __init__(self, font_size: int, scene_size: a, bg=(60, 60, 60)):
|
||||
def __init__(self, scene_size: a, bg=(60, 60, 60)):
|
||||
|
||||
s__size = [600, 400]
|
||||
|
||||
super().__init__(s__size[0], s__size[1], font_size, scene_size, bg)
|
||||
super().__init__(s__size[0], s__size[1], scene_size, bg)
|
||||
|
||||
r0 = Rect(a([0, 0]), a([200, 200]), (160, 160, 160), self)
|
||||
self.r_objects.append(r0)
|
||||
@ -27,3 +28,6 @@ class BasicScene(Scene):
|
||||
|
||||
e0 = Ellipse(a([150, 360]), 60, 20, (100, 255, 100), self)
|
||||
self.nr_objects.append(e0)
|
||||
|
||||
t0 = Text(a([100, 50]), "hello world!", 26, (200, 200, 200), self)
|
||||
self.nr_objects.append(t0)
|
||||
|
@ -7,9 +7,9 @@ screen_size = a([200, 500])
|
||||
|
||||
|
||||
for i in range(400):
|
||||
scene = BasicScene(10, screen_size)
|
||||
scene = BasicScene(screen_size)
|
||||
scene.redraw()
|
||||
#scene.save(f"Render/{i}.png")
|
||||
# scene.save(f"Render/{i}.png", [800, 800])
|
||||
|
||||
if i < 150:
|
||||
screen_size[0] += 3
|
||||
|
Loading…
Reference in New Issue
Block a user