from simulator.graphics import Screen

import pygame as pg

if __name__ == "__main__":
    b1 = Body(Vector2(0, 0), velocity=Vector2(0, 0), mass=10, draw_radius=10)
    b2 = Body(Vector2(1, 1), velocity=Vector2(0, 0.2), mass=1, draw_radius=5)

    world = World()
    world.add(b1)
    world.add(b2)

    simulator = Simulator(world, LessDummyEngine, DummySolver)

    screen_size = Vector2(800, 600)
    screen = Screen(screen_size, bg_color=(0, 0, 0), caption="Simulator")
    screen.camera.scale = 50

    # this coefficient controls the speed
    # of the simulation
    time_scale = 10

    print("Start program")
    while not screen.should_quit:
        dt = screen.tick(60)

        # simulate physics
        delta_time = time_scale * dt / 1000
        simulator.step(delta_time)

        # read events
                                                 [[-0.2, 0.2], [-0.2, 0.2]],
                                                 100)

    # Choix des monde :
    mondes_simulés = [
        systeme_solaire, monde_pour_collision, monde_aléatoire,
        monde_aléatoire_geant
    ]
    #mondes_simulés=[monde_aléatoire_geant]
    print("Start program")
    for world in mondes_simulés:
        simulator = Simulator(world, SimpleAvecCollisonEngine, DummySolver)

        screen_size = Vector2(1000, 1000)
        screen = Screen(screen_size,
                        bg_color=world.bg_color,
                        caption="Simulator")
        screen.camera.scale = world.camera_scale_initial

        # this coefficient controls the speed
        # of the simulation
        time_scale = world.time_scale

        print("  ", world.nom, "avec", len(world), "corps.")
        orbites = []

        while not screen.should_quit:

            ## Dessin et Calcul du prochain état
            # -O activé (->on dessine les orbites)
            if screen.get_touche_o():
Example #3
0
            draw_radius = 2 * real_radius
            b = Body(position, velocity, mass, color, real_radius, draw_radius)
            world.add(b)

    f.close()

    #Permet de contrôler l'affichage des traçantes
    should_erase_background = True

    #simulator = Simulator(world, DummyEngine, DummySolver)
    #simulator = Simulator(world, BarnesHutEngine, DummySolver)
    simulator = Simulator(world, DummyEngine, LeapFrogSolver)
    #simulator = Simulator(world, BarnesHutEngine, LeapFrogSolver)

    screen_size = Vector2(800, 600)
    screen = Screen(screen_size, bg_color=(0, 0, 0), caption="Simulator")

    # centrage de la caméra
    for b in world.bodies():
        screen.camera.position += b.position

    screen.camera.position /= len(world)

    # le bon scale (diagonale d'écran/ distance max entre body et la caméra)
    max_norm = 1
    for b in world.bodies():
        max_norm = max(max_norm, (b.position - screen.camera.position).norm())

    screen.camera.scale = screen_size.get_y() / max_norm / 2

    # this coefficient controls the speed
from ..utils.vector import Vector, Vector2
from .constants import G

from math import acos, asin, atan, cos, sin, tan, pi, sqrt, floor
from numpy import array, dot, transpose
from simulator.graphics import Screen

screen_size = Vector2(800, 600)
screen = Screen(screen_size,
                    bg_color=(0, 0, 0),
                    caption="Simulator")

def gravitational_force(pos1, mass1, pos2, mass2):
    """ Return the force applied to a body in pos1 with mass1
        by a body in pos2 with mass2
    """
    r=Vector.norm(pos1-pos2)
    Force2sur1=(-G*mass1*mass2/(r*r*r))*(pos1-pos2)
    return Force2sur1

def Rotation(theta, v):
    R=array([[cos(theta), -sin(theta)], [sin(theta),cos(theta)]])
    return dot(R,transpose(v))


class IEngine:
    def __init__(self, world):
        self.world = world
        self.n=len(self.world)
        if self.n>0 :
            self.dim=len(self.world._bodies[0].position)