_
This commit is contained in:
parent
009e23ea7f
commit
90154e37a8
2
.gitignore
vendored
2
.gitignore
vendored
@ -128,3 +128,5 @@ dmypy.json
|
|||||||
|
|
||||||
# Pyre type checker
|
# Pyre type checker
|
||||||
.pyre/
|
.pyre/
|
||||||
|
|
||||||
|
UI/Render
|
@ -1,7 +1,8 @@
|
|||||||
|
import copy
|
||||||
import math
|
import math
|
||||||
import pygame
|
import pygame
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
from Objects.Scene import Scene
|
from UI.Objects.Scene import Scene
|
||||||
|
|
||||||
|
|
||||||
class Multiscene(Scene):
|
class Multiscene(Scene):
|
||||||
@ -71,6 +72,15 @@ class Multiscene(Scene):
|
|||||||
|
|
||||||
self.resize_subscenes()
|
self.resize_subscenes()
|
||||||
|
|
||||||
|
def update_mouse_events(self, mouse_pos, clicked):
|
||||||
|
mouse_pos = a(mouse_pos)
|
||||||
|
self.mouse_pos = self.inverse_matrix @ mouse_pos
|
||||||
|
self.clicked = clicked
|
||||||
|
|
||||||
|
for subscene in self.subscenes:
|
||||||
|
subscene.mouse_pos = (subscene.inverse_matrix @ (mouse_pos - (self.matrix @ subscene.position)))
|
||||||
|
subscene.clicked = clicked
|
||||||
|
|
||||||
def progress(self):
|
def progress(self):
|
||||||
self.progress_subscenes()
|
self.progress_subscenes()
|
||||||
|
|
||||||
@ -82,6 +92,14 @@ class Multiscene(Scene):
|
|||||||
for subscene in self.subscenes:
|
for subscene in self.subscenes:
|
||||||
subscene.progress()
|
subscene.progress()
|
||||||
|
|
||||||
|
def get_i_objects(self):
|
||||||
|
i_objects = copy.copy(self.i_objects)
|
||||||
|
|
||||||
|
for subscene in self.subscenes:
|
||||||
|
i_objects += subscene.get_i_objects()
|
||||||
|
|
||||||
|
return i_objects
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def to_ints(iterable):
|
def to_ints(iterable):
|
||||||
for i in range(len(iterable)):
|
for i in range(len(iterable)):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import pygame.transform
|
import pygame.transform
|
||||||
from Objects.Screen import Screen
|
from UI.Objects.Screen import Screen
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
|
|
||||||
|
|
||||||
@ -14,6 +14,8 @@ class Scene(Screen):
|
|||||||
self.nrd_objects = [] # non-rescalable dynamic Objects
|
self.nrd_objects = [] # non-rescalable dynamic Objects
|
||||||
self.nrc_objects = [] # non-rescalable controllable Objects
|
self.nrc_objects = [] # non-rescalable controllable Objects
|
||||||
|
|
||||||
|
self.i_objects = [] # interactive Objects
|
||||||
|
|
||||||
self.position = a([0, 0])
|
self.position = a([0, 0])
|
||||||
self.multiscene = None
|
self.multiscene = None
|
||||||
|
|
||||||
@ -52,3 +54,6 @@ class Scene(Screen):
|
|||||||
|
|
||||||
def progress(self):
|
def progress(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_i_objects(self):
|
||||||
|
return self.i_objects
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import math
|
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
|
import math
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,13 +12,13 @@ class RopeInteractiveDot:
|
|||||||
self.scene = scene
|
self.scene = scene
|
||||||
|
|
||||||
def blit(self):
|
def blit(self):
|
||||||
pygame.draw.circle(self.scene.s, self.color, self.scene.matrix @ self.position, self.r)
|
pygame.draw.circle(self.scene.s, self.color, self.scene.matrix @ self.position, self.r * self.scene.pd_)
|
||||||
|
|
||||||
def input(self, mouse_pos, clicked):
|
def input(self, mouse_pos, clicked):
|
||||||
self.position = mouse_pos
|
self.position = mouse_pos
|
||||||
|
|
||||||
if clicked:
|
if clicked:
|
||||||
for object_ in self.scene.nrd_objects:
|
for object_ in self.scene.get_i_objects():
|
||||||
if object_.__class__.__name__ == "Rope":
|
if object_.__class__.__name__ == "Rope":
|
||||||
for node in object_.nodes:
|
for node in object_.nodes:
|
||||||
if node.locked is False:
|
if node.locked is False:
|
||||||
|
@ -36,7 +36,7 @@ class Rope:
|
|||||||
self.a.position = center - connection_vector
|
self.a.position = center - connection_vector
|
||||||
|
|
||||||
def __init__(self, position, length, nodes_n, nodes_r, rope_width, scene, gravity=2, start_angle=1,
|
def __init__(self, position, length, nodes_n, nodes_r, rope_width, scene, gravity=2, start_angle=1,
|
||||||
balance_amount=20, node_color=(255, 100, 100), rope_color=(255, 160, 160)):
|
balance_amount=10, node_color=(255, 100, 100), rope_color=(255, 160, 160)):
|
||||||
self.position = position
|
self.position = position
|
||||||
self.length = length
|
self.length = length
|
||||||
self.nodes_n = nodes_n
|
self.nodes_n = nodes_n
|
||||||
@ -76,6 +76,8 @@ class Rope:
|
|||||||
|
|
||||||
def blit(self):
|
def blit(self):
|
||||||
if self.pd_ != self.scene.pd_:
|
if self.pd_ != self.scene.pd_:
|
||||||
|
self.pd_ = self.scene.pd_
|
||||||
|
|
||||||
self.rescaled_rope_segment_length = self.rope_segment_length * self.pd_
|
self.rescaled_rope_segment_length = self.rope_segment_length * self.pd_
|
||||||
self.rescaled_nodes_r = self.nodes_r * self.pd_
|
self.rescaled_nodes_r = self.nodes_r * self.pd_
|
||||||
self.rescaled_rope_width = self.rope_width * self.pd_
|
self.rescaled_rope_width = self.rope_width * self.pd_
|
||||||
@ -87,10 +89,11 @@ class Rope:
|
|||||||
pygame.draw.line(self.scene.s, self.rope_color,
|
pygame.draw.line(self.scene.s, self.rope_color,
|
||||||
self.scene.matrix @ self.nodes[i].position,
|
self.scene.matrix @ self.nodes[i].position,
|
||||||
self.scene.matrix @ self.nodes[i + 1].position,
|
self.scene.matrix @ self.nodes[i + 1].position,
|
||||||
int(self.rescaled_rope_width))
|
max(1, int(self.rescaled_rope_width)))
|
||||||
|
|
||||||
for node in self.nodes:
|
for node in self.nodes:
|
||||||
pygame.draw.circle(self.scene.s, self.node_color, self.scene.matrix @ node.position, self.rescaled_nodes_r)
|
pygame.draw.circle(self.scene.s, self.node_color, self.scene.matrix @ node.position,
|
||||||
|
max(1, self.rescaled_nodes_r))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def to_ints(iterable):
|
def to_ints(iterable):
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from Objects.Multiscene import Multiscene
|
from UI.Objects.Multiscene import Multiscene
|
||||||
from Scenes.BasicScene import BasicScene
|
from UI.Scenes.BasicScene import BasicScene
|
||||||
from Objects.r_objects import *
|
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
|
|
||||||
from UI.Objects.nr_objects.Line import Line
|
from UI.Objects.nr_objects.Line import Line
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from Objects.Scene import Scene
|
from UI.Objects.Scene import Scene
|
||||||
from Objects.r_objects import *
|
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
|
|
||||||
from UI.Objects.nr_objects.Ellipse import Ellipse
|
from UI.Objects.nr_objects.Ellipse import Ellipse
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from Objects.Multiscene import Multiscene
|
from UI.Objects.Multiscene import Multiscene
|
||||||
from Scenes.BasicMultiscene import BasicMultiscene
|
from UI.Scenes.BasicMultiscene import BasicMultiscene
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
|
|
||||||
from UI.Objects.nr_objects.Line import Line
|
from UI.Objects.nr_objects.Line import Line
|
||||||
|
43
UI/Scenes/RopeMultiscene.py
Normal file
43
UI/Scenes/RopeMultiscene.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from numpy import array as a
|
||||||
|
|
||||||
|
from UI.Objects.Multiscene import Multiscene
|
||||||
|
from UI.Objects.nr_objects.Line import Line
|
||||||
|
from UI.Objects.nr_objects.controllable_objects.RopeInteractiveDot import RopeInteractiveDot
|
||||||
|
from UI.Scenes.RopeScene import RopeScene
|
||||||
|
|
||||||
|
|
||||||
|
class RopeMultiscene(Multiscene):
|
||||||
|
def __init__(self, scene_size):
|
||||||
|
|
||||||
|
self.s__size = [800, 400]
|
||||||
|
|
||||||
|
super().__init__(self.s__size[0], self.s__size[1], scene_size)
|
||||||
|
|
||||||
|
s0 = RopeScene([200, 400])
|
||||||
|
self.subscenes.append(s0)
|
||||||
|
|
||||||
|
s1 = RopeScene([600, 400])
|
||||||
|
s1.position = a([200, 0])
|
||||||
|
self.subscenes.append(s1)
|
||||||
|
|
||||||
|
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)
|
||||||
|
#self.nrc_objects.append(rd0)
|
||||||
|
|
||||||
|
self.i = 0
|
||||||
|
|
||||||
|
def progress(self):
|
||||||
|
if self.i == 1:
|
||||||
|
self.subscenes[0].subscene_size[0] += 2
|
||||||
|
self.subscenes[1].subscene_size[0] -= 2
|
||||||
|
self.subscenes[1].position[0] += 2
|
||||||
|
|
||||||
|
self.nr_objects[0].a[0] += 2
|
||||||
|
self.nr_objects[0].b[0] += 2
|
||||||
|
|
||||||
|
self.resize_subscenes()
|
||||||
|
self.i = 0
|
||||||
|
else:
|
||||||
|
self.i += 1
|
@ -1,4 +1,4 @@
|
|||||||
from Objects.Scene import Scene
|
from UI.Objects.Scene import Scene
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
@ -9,14 +9,15 @@ from UI.Objects.nr_objects.controllable_objects.RopeInteractiveDot import RopeIn
|
|||||||
class RopeScene(Scene):
|
class RopeScene(Scene):
|
||||||
def __init__(self, scene_size, bg=(60, 60, 60)):
|
def __init__(self, scene_size, bg=(60, 60, 60)):
|
||||||
|
|
||||||
s__size = [600, 400]
|
self.s__size = [600, 400]
|
||||||
|
|
||||||
super().__init__(s__size[0], 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, 40, 2, 2, self)
|
r0 = Rope(a([300, 50]), 200, 20, 2, 2, self)
|
||||||
self.nrd_objects.append(r0)
|
self.nrd_objects.append(r0)
|
||||||
|
self.i_objects.append(r0)
|
||||||
|
|
||||||
rd0 = RopeInteractiveDot(a([100, 100]), 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)
|
||||||
|
|
||||||
pygame.mouse.set_visible(False)
|
pygame.mouse.set_visible(False)
|
||||||
|
14
UI/main.py
14
UI/main.py
@ -1,15 +1,17 @@
|
|||||||
import pygame.mouse
|
import pygame.mouse
|
||||||
|
|
||||||
from Scenes.BasicScene import BasicScene
|
from UI.Scenes.BasicScene import BasicScene
|
||||||
from Scenes.BasicMultiscene import BasicMultiscene
|
from UI.Scenes.BasicMultiscene import BasicMultiscene
|
||||||
from Scenes.MultisceneInMultiscene import MultisceneInMultiscene
|
from UI.Scenes.MultisceneInMultiscene import MultisceneInMultiscene
|
||||||
from Scenes.RopeScene import RopeScene
|
from UI.Scenes.RopeScene import RopeScene
|
||||||
|
from UI.Scenes.RopeMultiscene import RopeMultiscene
|
||||||
|
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
screen_size = a([200, 500])
|
screen_size = a([200, 500])
|
||||||
scene = MultisceneInMultiscene(screen_size)
|
scene = RopeScene(screen_size)
|
||||||
|
|
||||||
mouse_pos = [0, 0]
|
mouse_pos = [0, 0]
|
||||||
clicked = False
|
clicked = False
|
||||||
@ -20,7 +22,7 @@ for i in range(400):
|
|||||||
scene.update()
|
scene.update()
|
||||||
scene.update_mouse_events(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3)[0])
|
scene.update_mouse_events(pygame.mouse.get_pos(), pygame.mouse.get_pressed(3)[0])
|
||||||
scene.progress()
|
scene.progress()
|
||||||
scene.save(f"Render/{i}.png", [800, 800])
|
#scene.save(f"Render/{i}.png", [800, 800])
|
||||||
|
|
||||||
if i < 150:
|
if i < 150:
|
||||||
screen_size[0] += 3
|
screen_size[0] += 3
|
||||||
|
Loading…
Reference in New Issue
Block a user