From cd3d01db4052b425df4a82be4499eefb92215ce7 Mon Sep 17 00:00:00 2001 From: Elias Dobrin Date: Tue, 5 Sep 2023 16:09:43 -0700 Subject: [PATCH] Removed node-plate collision. --- softquake/main.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/softquake/main.py b/softquake/main.py index 37e1a71..7f6c06f 100644 --- a/softquake/main.py +++ b/softquake/main.py @@ -1,4 +1,4 @@ -from math import tau, sqrt, atan2, floor, cos, sin +from math import tau, sqrt, atan2, floor from os import path, mkdir, rmdir, remove from glob import glob from time import sleep @@ -286,7 +286,7 @@ class Style: print(" Spring Stiffness Diagram") print( rf""" - {Fore.LIGHTWHITE_EX}D{Fore.RED}---^{Fore.LIGHTRED_EX}\/\/\/\/\/\/{Fore.RED}^---{Fore.LIGHTWHITE_EX}O : {Fore.LIGHTGREEN_EX}{stiffness:.2e} {Fore.LIGHTGREEN_EX}N/m{Fore.LIGHTWHITE_EX} + {Fore.LIGHTWHITE_EX}{Back.BLUE}D{Back.RESET}{Fore.RED}---^{Fore.LIGHTRED_EX}\/\/\/\/\/\/{Fore.RED}^---{Fore.LIGHTWHITE_EX}{Back.BLUE}O{Back.RESET} : {Fore.LIGHTGREEN_EX}{stiffness:.2e} {Fore.LIGHTGREEN_EX}N/m{Fore.LIGHTWHITE_EX} """ ) @@ -309,7 +309,7 @@ class Style: print(" Spring Dampening Diagram") print( rf""" - {Fore.LIGHTWHITE_EX}D{Fore.RED}--------[{Fore.LIGHTRED_EX}::{Fore.RED}|--------{Fore.LIGHTWHITE_EX}O : {Fore.LIGHTGREEN_EX}{dampening:.2e} {Fore.LIGHTGREEN_EX}N*s/m{Fore.LIGHTWHITE_EX} + {Fore.LIGHTWHITE_EX}{Back.BLUE}D{Back.RESET}{Fore.RED}--------[{Fore.LIGHTRED_EX}::{Fore.RED}|--------{Fore.LIGHTWHITE_EX}{Back.BLUE}O{Back.RESET} : {Fore.LIGHTGREEN_EX}{dampening:.2e} {Fore.LIGHTGREEN_EX}N*s/m{Fore.LIGHTWHITE_EX} """ ) @@ -322,11 +322,11 @@ class Style: amplitude = 0.0 if frequency == "Low": - frequency = 0.2 + frequency = 0.25 amplitude = 2.0 elif frequency == "Medium": frequency = 2.0 - amplitude = 0.2 + amplitude = 0.4 elif frequency == "High": frequency = 10.0 amplitude = 0.05 @@ -337,7 +337,7 @@ class Style: print( rf""" {Fore.BLUE} .{Fore.LIGHTBLUE_EX}_________. {Fore.LIGHTWHITE_EX} : {Fore.LIGHTGREEN_EX}{frequency:.2f} {Fore.LIGHTGREEN_EX}Hz - {Fore.LIGHTWHITE_EX}<--{Fore.BLUE}|_________{Fore.LIGHTBLUE_EX}|{Fore.LIGHTWHITE_EX}--> {Fore.LIGHTWHITE_EX}: {Fore.LIGHTGREEN_EX}{amplitude:.2f} {Fore.LIGHTGREEN_EX}m{Fore.LIGHTWHITE_EX} + {Fore.LIGHTWHITE_EX}{Back.BLUE}<--{Back.RESET}{Fore.BLUE}|_________{Fore.LIGHTBLUE_EX}|{Fore.LIGHTWHITE_EX}{Back.BLUE}-->{Back.RESET} {Fore.LIGHTWHITE_EX}: {Fore.LIGHTGREEN_EX}{amplitude:.2f} {Fore.LIGHTGREEN_EX}m{Fore.LIGHTWHITE_EX} """ ) @@ -543,8 +543,11 @@ def add_link_maybe(n1, n2): dist = Vector.dist(node1.position, node2.position) if 0.01 < dist < 0.75: - vector = Vector((node1.position.x - node2.position.x) / dist, - (node1.position.y - node2.position.y) / dist) + try: + vector = Vector((node1.position.x - node2.position.x) / dist, + (node1.position.y - node2.position.y) / dist) + except ZeroDivisionError: + vector = Vector(0, 0) dx = 0.75 - dist node1.force.x += 4e6 * dx * vector.x node1.force.y += 4e6 * dx * vector.y @@ -560,15 +563,6 @@ def add_link_maybe(n1, n2): ) node.velocity += 0.5 * (acceleration + node.acceleration) * delta - for node in nodes: - if plate.position.x - 0.5 * plate.width < node.position.x < plate.position.x + 0.5 * plate.width: - if node.position.x < plate.position.x: - node.position.x = plate.position.x - 0.5 * plate.width - else: - node.position.x = plate.position.x + 0.5 * plate.width - if node.position.y < plate.position.y: - node.position.y = plate.position.y - energy = 0.0 epotenergy = 0.0 kinenergy = 0.0