From 27a62277a615c7dcf684c0d0ca94683090111391 Mon Sep 17 00:00:00 2001 From: Crizomb <62544756+Crizomb@users.noreply.github.com> Date: Tue, 14 Feb 2023 12:57:26 +0100 Subject: [PATCH] performances + blackhole added __slots__ to the Node class + added central black hole at the center of the galaxy in create_stars --- barnes-hut-galaxy-new.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/barnes-hut-galaxy-new.py b/barnes-hut-galaxy-new.py index 7252e55..1bbd5de 100644 --- a/barnes-hut-galaxy-new.py +++ b/barnes-hut-galaxy-new.py @@ -48,6 +48,7 @@ class Star: class Node: """"Node class""" + __slots__ = "center", "center_of_mass", "mass", "children", "width" def __init__(self, center: Vec3, center_of_mass: Vec3, mass: float, children, width: float): self.center = center self.center_of_mass = center_of_mass @@ -132,6 +133,10 @@ def create_stars(nb_stars: int) -> List[Star]: orthog = Vec3(1, 0, -x / z) if z > 0 else Vec3(-1, 0, x / z) speed = orthog.normalize()*pos.norm stars.append(Star(pos, speed, 1)) + + #add center blackhole + stars.append(Star(Vec3(0, 0, 0), Vec3(0, 0, 0), nb_stars/10)) + return stars def create_tree(stars: List[Star]) -> Node: