_
This commit is contained in:
parent
a0c7caf727
commit
e112ce52e3
@ -6,6 +6,9 @@ from UI.Objects.Scene import Scene
|
|||||||
|
|
||||||
|
|
||||||
class Multiscene(Scene):
|
class Multiscene(Scene):
|
||||||
|
|
||||||
|
object_type = "multiscene"
|
||||||
|
|
||||||
def __init__(self, width: float, height: float, scene_size: a):
|
def __init__(self, width: float, height: float, scene_size: a):
|
||||||
super().__init__(width, height, scene_size)
|
super().__init__(width, height, scene_size)
|
||||||
|
|
||||||
@ -39,12 +42,10 @@ class Multiscene(Scene):
|
|||||||
for object_ in self.nr_objects:
|
for object_ in self.nr_objects:
|
||||||
object_.blit()
|
object_.blit()
|
||||||
|
|
||||||
for object_ in self.nrd_objects:
|
for object_ in self.d_objects:
|
||||||
object_.blit()
|
|
||||||
object_.progress()
|
object_.progress()
|
||||||
|
|
||||||
for object_ in self.nrc_objects:
|
for object_ in self.c_objects:
|
||||||
object_.blit()
|
|
||||||
object_.input(self.mouse_pos, self.clicked)
|
object_.input(self.mouse_pos, self.clicked)
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
|
@ -4,6 +4,9 @@ from numpy import array as a
|
|||||||
|
|
||||||
|
|
||||||
class Scene(Screen):
|
class Scene(Screen):
|
||||||
|
|
||||||
|
object_type = "scene"
|
||||||
|
|
||||||
def __init__(self, width: float, height: float, scene_size: a, bg=(60, 60, 60)):
|
def __init__(self, width: float, height: float, scene_size: a, bg=(60, 60, 60)):
|
||||||
super().__init__(width, height, scene_size)
|
super().__init__(width, height, scene_size)
|
||||||
|
|
||||||
@ -11,9 +14,8 @@ class Scene(Screen):
|
|||||||
self.r_objects = [] # resizable Objects
|
self.r_objects = [] # resizable Objects
|
||||||
self.nr_objects = [] # non-rescalable Objects
|
self.nr_objects = [] # non-rescalable Objects
|
||||||
|
|
||||||
self.nrd_objects = [] # non-rescalable dynamic Objects
|
self.d_objects = [] # dynamic Objects
|
||||||
self.nrc_objects = [] # non-rescalable controllable Objects
|
self.c_objects = [] # controllable Objects
|
||||||
|
|
||||||
self.i_objects = [] # interactive Objects
|
self.i_objects = [] # interactive Objects
|
||||||
|
|
||||||
self.position = a([0, 0])
|
self.position = a([0, 0])
|
||||||
@ -34,12 +36,10 @@ class Scene(Screen):
|
|||||||
for object_ in self.nr_objects:
|
for object_ in self.nr_objects:
|
||||||
object_.blit()
|
object_.blit()
|
||||||
|
|
||||||
for object_ in self.nrd_objects:
|
for object_ in self.d_objects:
|
||||||
object_.blit()
|
|
||||||
object_.progress()
|
object_.progress()
|
||||||
|
|
||||||
for object_ in self.nrc_objects:
|
for object_ in self.c_objects:
|
||||||
object_.blit()
|
|
||||||
object_.input(self.mouse_pos, self.clicked)
|
object_.input(self.mouse_pos, self.clicked)
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
@ -57,3 +57,23 @@ class Scene(Screen):
|
|||||||
|
|
||||||
def get_i_objects(self):
|
def get_i_objects(self):
|
||||||
return [[self.i_objects, self.mouse_pos]]
|
return [[self.i_objects, self.mouse_pos]]
|
||||||
|
|
||||||
|
def sort_objects(self, *args):
|
||||||
|
for object_ in args:
|
||||||
|
for object_tag in object_.object_type.split("_"):
|
||||||
|
if object_tag == "r":
|
||||||
|
self.r_objects.append(object_)
|
||||||
|
elif object_tag == "nr":
|
||||||
|
self.nr_objects.append(object_)
|
||||||
|
elif object_tag == "d":
|
||||||
|
self.d_objects.append(object_)
|
||||||
|
elif object_tag == "c":
|
||||||
|
self.c_objects.append(object_)
|
||||||
|
elif object_tag == "i":
|
||||||
|
self.i_objects.append(object_)
|
||||||
|
elif object_tag in ["scene", "multiscene"]:
|
||||||
|
if self.object_type == "multiscene":
|
||||||
|
self.subscenes.append(object_)
|
||||||
|
else:
|
||||||
|
raise ValueError("Scene/Multiscene object encountered in scene.sort_objects()\n"
|
||||||
|
"Please use Multiscene for this purpose.")
|
||||||
|
@ -2,6 +2,9 @@ import pygame.draw
|
|||||||
|
|
||||||
|
|
||||||
class Circle:
|
class Circle:
|
||||||
|
|
||||||
|
object_type = "nr"
|
||||||
|
|
||||||
def __init__(self, center, radius, color, scene):
|
def __init__(self, center, radius, color, scene):
|
||||||
self.center = center
|
self.center = center
|
||||||
self.radius = radius
|
self.radius = radius
|
||||||
|
@ -2,6 +2,9 @@ import pygame
|
|||||||
|
|
||||||
|
|
||||||
class Ellipse:
|
class Ellipse:
|
||||||
|
|
||||||
|
object_type = "nr"
|
||||||
|
|
||||||
def __init__(self, center, a, b, color, scene):
|
def __init__(self, center, a, b, color, scene):
|
||||||
self.center = center
|
self.center = center
|
||||||
self.a = a
|
self.a = a
|
||||||
|
@ -4,6 +4,9 @@ import math
|
|||||||
|
|
||||||
|
|
||||||
class EquilateralTriangle:
|
class EquilateralTriangle:
|
||||||
|
|
||||||
|
object_type = "nr"
|
||||||
|
|
||||||
def __init__(self, position, side_length, rotation, color, scene, width=0):
|
def __init__(self, position, side_length, rotation, color, scene, width=0):
|
||||||
self.position = position
|
self.position = position
|
||||||
self.side_length = side_length
|
self.side_length = side_length
|
||||||
|
@ -5,6 +5,9 @@ import copy
|
|||||||
|
|
||||||
|
|
||||||
class Image:
|
class Image:
|
||||||
|
|
||||||
|
object_type = "nr"
|
||||||
|
|
||||||
def __init__(self, center, scalar, path, scene):
|
def __init__(self, center, scalar, path, scene):
|
||||||
self.center = center
|
self.center = center
|
||||||
self.scalar = scalar
|
self.scalar = scalar
|
||||||
|
@ -2,6 +2,9 @@ import pygame.draw
|
|||||||
|
|
||||||
|
|
||||||
class Line:
|
class Line:
|
||||||
|
|
||||||
|
object_type = "nr"
|
||||||
|
|
||||||
def __init__(self, a, b, width, color, scene):
|
def __init__(self, a, b, width, color, scene):
|
||||||
self.a = a
|
self.a = a
|
||||||
self.b = b
|
self.b = b
|
||||||
|
@ -2,6 +2,9 @@ import pygame
|
|||||||
|
|
||||||
|
|
||||||
class Text:
|
class Text:
|
||||||
|
|
||||||
|
object_type = "nr"
|
||||||
|
|
||||||
def __init__(self, position, text, font_size, color, scene, font_name="calibri", bold=True):
|
def __init__(self, position, text, font_size, color, scene, font_name="calibri", bold=True):
|
||||||
self.position = position
|
self.position = position
|
||||||
self.text = text
|
self.text = text
|
||||||
|
@ -3,6 +3,9 @@ import pygame
|
|||||||
|
|
||||||
|
|
||||||
class RopeInteractiveDot:
|
class RopeInteractiveDot:
|
||||||
|
|
||||||
|
object_type = "nr_c"
|
||||||
|
|
||||||
def __init__(self, position, r, color, force, forcefield_range, scene):
|
def __init__(self, position, r, color, force, forcefield_range, scene):
|
||||||
self.position = position
|
self.position = position
|
||||||
self.r = r
|
self.r = r
|
||||||
@ -25,7 +28,8 @@ class RopeInteractiveDot:
|
|||||||
if node.locked is False:
|
if node.locked is False:
|
||||||
if math.sqrt(sum((node.position - self.position) ** 2)) < self.forcefield_range:
|
if math.sqrt(sum((node.position - self.position) ** 2)) < self.forcefield_range:
|
||||||
force_vector = node.position - self.position
|
force_vector = node.position - self.position
|
||||||
full_force_vector = (force_vector / math.sqrt(sum(force_vector ** 2))) * self.forcefield_range
|
full_force_vector = (force_vector / math.sqrt(sum(force_vector ** 2))) \
|
||||||
|
* self.forcefield_range
|
||||||
force_vector = full_force_vector - force_vector
|
force_vector = full_force_vector - force_vector
|
||||||
force_vector /= self.forcefield_range / self.force
|
force_vector /= self.forcefield_range / self.force
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import math
|
|||||||
|
|
||||||
class Rope:
|
class Rope:
|
||||||
|
|
||||||
|
object_type = "nr_d_i"
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, position):
|
def __init__(self, position):
|
||||||
self.position = position
|
self.position = position
|
||||||
|
@ -2,6 +2,9 @@ import pygame.draw
|
|||||||
|
|
||||||
|
|
||||||
class Rect:
|
class Rect:
|
||||||
|
|
||||||
|
object_type = "r"
|
||||||
|
|
||||||
def __init__(self, pos, size, color, scene):
|
def __init__(self, pos, size, color, scene):
|
||||||
self.pos = pos
|
self.pos = pos
|
||||||
self.size = size
|
self.size = size
|
||||||
|
@ -13,14 +13,13 @@ class BasicMultiscene(Multiscene):
|
|||||||
super().__init__(self.s__size[0], self.s__size[1], scene_size)
|
super().__init__(self.s__size[0], self.s__size[1], scene_size)
|
||||||
|
|
||||||
s0 = BasicScene([200, 400])
|
s0 = BasicScene([200, 400])
|
||||||
self.subscenes.append(s0)
|
|
||||||
|
|
||||||
s1 = BasicScene([400, 400])
|
s1 = BasicScene([400, 400])
|
||||||
s1.position = a([200, 0])
|
s1.position = a([200, 0])
|
||||||
self.subscenes.append(s1)
|
|
||||||
|
|
||||||
l0 = Line(a([200, 0]), a([200, 400]), 10, (255, 100, 100), self)
|
l0 = Line(a([200, 0]), a([200, 400]), 10, (255, 100, 100), self)
|
||||||
self.nr_objects.append(l0)
|
|
||||||
|
self.sort_objects(s0, s1, l0)
|
||||||
|
|
||||||
self.i = 0
|
self.i = 0
|
||||||
|
|
||||||
|
@ -18,22 +18,17 @@ class BasicScene(Scene):
|
|||||||
super().__init__(self.s__size[0], self.s__size[1], scene_size, bg)
|
super().__init__(self.s__size[0], self.s__size[1], scene_size, bg)
|
||||||
|
|
||||||
r0 = Rect(a([0, 0]), a([200, 200]), (160, 160, 160), self)
|
r0 = Rect(a([0, 0]), a([200, 200]), (160, 160, 160), self)
|
||||||
self.r_objects.append(r0)
|
|
||||||
|
|
||||||
l0 = Line(a([100, 300]), a([500, 100]), 3, (255, 100, 100), self)
|
l0 = Line(a([100, 300]), a([500, 100]), 3, (255, 100, 100), self)
|
||||||
self.nr_objects.append(l0)
|
|
||||||
|
|
||||||
c0 = Circle(a([400, 200]), 40, (100, 100, 255), self)
|
c0 = Circle(a([400, 200]), 40, (100, 100, 255), self)
|
||||||
self.nr_objects.append(c0)
|
|
||||||
|
|
||||||
e0 = Ellipse(a([150, 360]), 60, 20, (100, 255, 100), self)
|
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)
|
t0 = Text(a([100, 50]), "hello world!", 26, (200, 200, 200), self)
|
||||||
self.nr_objects.append(t0)
|
|
||||||
|
|
||||||
i0 = Image(a([200, 0]), 0.8, "test.png", self)
|
i0 = Image(a([200, 0]), 0.8, "test.png", self)
|
||||||
self.nr_objects.append(i0)
|
|
||||||
|
|
||||||
t0 = EquilateralTriangle(a([500, 300]), 30, 1, (250, 250, 150), self)
|
triangle0 = EquilateralTriangle(a([500, 300]), 30, 1, (250, 250, 150), self)
|
||||||
self.nr_objects.append(t0)
|
|
||||||
|
self.sort_objects(r0, l0, c0, e0, t0, i0, triangle0)
|
||||||
|
@ -12,14 +12,13 @@ class MultisceneInMultiscene(Multiscene):
|
|||||||
super().__init__(self.s__size[0], self.s__size[1], scene_size)
|
super().__init__(self.s__size[0], self.s__size[1], scene_size)
|
||||||
|
|
||||||
ms0 = BasicMultiscene([600, 400])
|
ms0 = BasicMultiscene([600, 400])
|
||||||
self.subscenes.append(ms0)
|
|
||||||
|
|
||||||
ms1 = BasicMultiscene([600, 400])
|
ms1 = BasicMultiscene([600, 400])
|
||||||
ms1.position = a([0, 400])
|
ms1.position = a([0, 400])
|
||||||
self.subscenes.append(ms1)
|
|
||||||
|
|
||||||
l0 = Line(a([0, 400]), a([600, 400]), 12, (100, 100, 255), self)
|
l0 = Line(a([0, 400]), a([600, 400]), 12, (100, 100, 255), self)
|
||||||
self.nr_objects.append(l0)
|
|
||||||
|
self.sort_objects(ms0, ms1, l0)
|
||||||
|
|
||||||
self.i = 0
|
self.i = 0
|
||||||
|
|
||||||
|
@ -14,18 +14,17 @@ class RopeMultiscene(Multiscene):
|
|||||||
super().__init__(self.s__size[0], self.s__size[1], scene_size)
|
super().__init__(self.s__size[0], self.s__size[1], scene_size)
|
||||||
|
|
||||||
s0 = RopeScene([200, 400])
|
s0 = RopeScene([200, 400])
|
||||||
self.subscenes.append(s0)
|
|
||||||
|
|
||||||
s1 = RopeScene([600, 400])
|
s1 = RopeScene([600, 400])
|
||||||
s1.position = a([200, 0])
|
s1.position = a([200, 0])
|
||||||
self.subscenes.append(s1)
|
|
||||||
|
|
||||||
l0 = Line(a([200, 0]), a([200, 400]), 10, (255, 100, 100), self)
|
l0 = Line(a([200, 0]), a([200, 400]), 10, (255, 100, 100), self)
|
||||||
self.nr_objects.append(l0)
|
|
||||||
|
|
||||||
rd0 = RopeInteractiveDot(a([0, 0]), 10, (100, 255, 100), 20, 100, self)
|
rd0 = RopeInteractiveDot(a([0, 0]), 10, (100, 255, 100), 20, 100, self)
|
||||||
#self.nrc_objects.append(rd0)
|
#self.nrc_objects.append(rd0)
|
||||||
|
|
||||||
|
self.sort_objects(s0, s1, l0)
|
||||||
|
|
||||||
self.i = 0
|
self.i = 0
|
||||||
|
|
||||||
def progress(self):
|
def progress(self):
|
||||||
|
@ -14,10 +14,9 @@ class RopeScene(Scene):
|
|||||||
super().__init__(self.s__size[0], self.s__size[1], scene_size, bg)
|
super().__init__(self.s__size[0], self.s__size[1], scene_size, bg)
|
||||||
|
|
||||||
r0 = Rope(a([300, 50]), 200, 20, 2, 2, self)
|
r0 = Rope(a([300, 50]), 200, 20, 2, 2, self)
|
||||||
self.nrd_objects.append(r0)
|
|
||||||
self.i_objects.append(r0)
|
|
||||||
|
|
||||||
rd0 = RopeInteractiveDot(a([0, 0]), 10, (100, 255, 100), 20, 100, self)
|
rd0 = RopeInteractiveDot(a([0, 0]), 10, (100, 255, 100), 20, 100, self)
|
||||||
self.nrc_objects.append(rd0)
|
|
||||||
|
self.sort_objects(r0, rd0)
|
||||||
|
|
||||||
pygame.mouse.set_visible(False)
|
pygame.mouse.set_visible(False)
|
||||||
|
@ -11,7 +11,7 @@ import time
|
|||||||
|
|
||||||
|
|
||||||
screen_size = a([200, 500])
|
screen_size = a([200, 500])
|
||||||
scene = RopeScene(screen_size)
|
scene = RopeMultiscene(screen_size)
|
||||||
|
|
||||||
mouse_pos = [0, 0]
|
mouse_pos = [0, 0]
|
||||||
clicked = False
|
clicked = False
|
||||||
|
Loading…
Reference in New Issue
Block a user