This commit is contained in:
Benjamín 2021-09-13 20:03:31 +02:00
parent d715ffb7ef
commit 1e3e7939b0
3 changed files with 47 additions and 12 deletions

@ -27,9 +27,12 @@ class Multiscene(Scene):
self.subscenes_prepared = True self.subscenes_prepared = True
def light_update(self): def light_update(self):
for subscene in self.subscenes:
subscene.light_update()
for object_ in self.l_objects: for object_ in self.l_objects:
object_.update() object_.update()
object_.blit() object_.blit(True)
pygame.display.update() pygame.display.update()

@ -1,6 +1,7 @@
import pygame.transform import pygame.transform
from UI.Objects.Screen import Screen from UI.Objects.Screen import Screen
from numpy import array as a from numpy import array as a
import numpy as np
class Scene(Screen): class Scene(Screen):
@ -28,7 +29,7 @@ class Scene(Screen):
def light_update(self): def light_update(self):
for object_ in self.l_objects: for object_ in self.l_objects:
object_.update() object_.update()
object_.blit() object_.blit(True)
pygame.display.update() pygame.display.update()
@ -69,6 +70,22 @@ 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 get_info_for_light_objects(self, position):
s = self
positions = [position]
matrices = [self.matrix]
while s.multiscene is not None:
positions.append(s.position)
s = s.multiscene
matrices.append(s.matrix)
transformed_position = a([0., 0.])
for p, m in zip(positions, matrices):
transformed_position += a(m @ p)
return s.s, transformed_position
def sort_objects(self, *args): def sort_objects(self, *args):
for object_ in args: for object_ in args:
for object_tag in object_.object_type.split("_"): for object_tag in object_.object_type.split("_"):

@ -52,7 +52,22 @@ class LuminousCircleEffect:
self.point_velocity /= math.sqrt(sum(self.point_velocity ** 2)) self.point_velocity /= math.sqrt(sum(self.point_velocity ** 2))
self.point_velocity *= self.point_speed self.point_velocity *= self.point_speed
def blit(self): def blit(self, light_blit=False):
if light_blit:
s, transformed_position = self.scene.get_info_for_light_objects(self.position)
rescaled_r = self.r * self.scene.pd_
x = np.linspace(0, self.point_position[0], self.circles_n) * rescaled_r
y = np.linspace(0, self.point_position[1], self.circles_n) * rescaled_r
r = np.linspace(rescaled_r, 0, self.circles_n)
c = [np.linspace(value, 255, self.circles_n) for value in self.color]
for i in range(self.circles_n - 1):
circle(s, (c[0][i], c[1][i], c[2][i]),
transformed_position + array([x[i], y[i]]), r[i])
else:
rescaled_r = self.r * self.scene.pd_ rescaled_r = self.r * self.scene.pd_
transformed_position = self.scene.matrix @ self.position transformed_position = self.scene.matrix @ self.position