_
This commit is contained in:
parent
4b97fda8f2
commit
2cd4b781fb
@ -21,10 +21,12 @@ class RopeInteractiveDot:
|
|||||||
for object_ in self.scene.nrd_objects:
|
for object_ in self.scene.nrd_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 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
|
||||||
force_vector /= math.sqrt(sum(force_vector ** 2))
|
full_force_vector = (force_vector / math.sqrt(sum(force_vector ** 2))) * self.forcefield_range
|
||||||
force_vector *= self.force
|
force_vector = full_force_vector - force_vector
|
||||||
|
force_vector /= self.forcefield_range / self.force
|
||||||
|
|
||||||
node.position += force_vector
|
node.position += force_vector
|
||||||
|
|
||||||
|
@ -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=1, start_angle=1,
|
def __init__(self, position, length, nodes_n, nodes_r, rope_width, scene, gravity=1, start_angle=1,
|
||||||
node_color=(255, 100, 100), rope_color=(255, 160, 160)):
|
balance_amount=20, 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
|
||||||
@ -44,6 +44,7 @@ class Rope:
|
|||||||
self.rope_width = rope_width
|
self.rope_width = rope_width
|
||||||
self.gravity = gravity
|
self.gravity = gravity
|
||||||
self.start_angle = start_angle
|
self.start_angle = start_angle
|
||||||
|
self.balance_amount = balance_amount
|
||||||
self.scene = scene
|
self.scene = scene
|
||||||
self.node_color = node_color
|
self.node_color = node_color
|
||||||
self.rope_color = rope_color
|
self.rope_color = rope_color
|
||||||
@ -69,7 +70,7 @@ class Rope:
|
|||||||
for node in self.nodes:
|
for node in self.nodes:
|
||||||
node.progress(self.gravity)
|
node.progress(self.gravity)
|
||||||
|
|
||||||
for _ in range(6):
|
for _ in range(self.balance_amount):
|
||||||
for connection in self.connections:
|
for connection in self.connections:
|
||||||
connection.balance()
|
connection.balance()
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from Objects.Scene import Scene
|
from Objects.Scene import Scene
|
||||||
from numpy import array as a
|
from numpy import array as a
|
||||||
|
import pygame
|
||||||
|
|
||||||
from UI.Objects.nr_objects.dynamic_objects.Rope import Rope
|
from UI.Objects.nr_objects.dynamic_objects.Rope import Rope
|
||||||
from UI.Objects.nr_objects.controllable_objects.RopeInteractiveDot import RopeInteractiveDot
|
from UI.Objects.nr_objects.controllable_objects.RopeInteractiveDot import RopeInteractiveDot
|
||||||
@ -12,8 +13,10 @@ class RopeScene(Scene):
|
|||||||
|
|
||||||
super().__init__(s__size[0], s__size[1], scene_size, bg)
|
super().__init__(s__size[0], s__size[1], scene_size, bg)
|
||||||
|
|
||||||
r0 = Rope(a([300, 50]), 400, 20, 2, 2, self, gravity=5)
|
r0 = Rope(a([300, 50]), 200, 40, 2, 2, self, gravity=2)
|
||||||
self.nrd_objects.append(r0)
|
self.nrd_objects.append(r0)
|
||||||
|
|
||||||
rd0 = RopeInteractiveDot(a([100, 100]), 20, (100, 255, 100), 5, 100, self)
|
rd0 = RopeInteractiveDot(a([100, 100]), 10, (100, 255, 100), 20, 100, self)
|
||||||
self.nrc_objects.append(rd0)
|
self.nrc_objects.append(rd0)
|
||||||
|
|
||||||
|
pygame.mouse.set_visible(False)
|
||||||
|
@ -9,7 +9,7 @@ import time
|
|||||||
|
|
||||||
|
|
||||||
screen_size = a([200, 500])
|
screen_size = a([200, 500])
|
||||||
scene = RopeScene(screen_size)
|
scene = MultisceneInMultiscene(screen_size)
|
||||||
|
|
||||||
mouse_pos = [0, 0]
|
mouse_pos = [0, 0]
|
||||||
clicked = False
|
clicked = False
|
||||||
@ -20,7 +20,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