From: Skullheadx Date: Sun, 9 Jun 2024 00:21:35 +0000 (-0400) Subject: added readme and qol changes X-Git-Url: http://git.skullheadx.com/nixos/static/gitweb.js?a=commitdiff_plain;h=60c14933ecb0551116ce103fa7476e13d3147eeb;p=Electric-Dipoles.git added readme and qol changes --- diff --git a/main.py b/main.py index 7f6ac5e..74f1c7f 100644 --- a/main.py +++ b/main.py @@ -5,11 +5,16 @@ is_running = True clock = pygame.Clock() delta = 0 -particles = [PointParticle((SCREEN_WIDTH / 3, SCREEN_HEIGHT / 2), 1.6e-19), - PointParticle((SCREEN_WIDTH * 2 / 3, SCREEN_HEIGHT / 2), -1.6e-19), - PointParticle((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2), 1.6e-19)] +particles = [ + PointParticle((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2), -1.6e-19), + PointParticle((SCREEN_WIDTH / 3, SCREEN_HEIGHT / 2), 1.6e-19), + # PointParticle((SCREEN_WIDTH * 2 / 3, SCREEN_HEIGHT / 2), 1.6e-19), + # PointParticle((SCREEN_WIDTH / 2, SCREEN_HEIGHT * 2 / 3), 1.6e-19), + # PointParticle((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 3), 1.6e-19), + ] while is_running: + pygame.display.set_caption(f"Electric Dipoles - {round(clock.get_fps())} FPS") for event in pygame.event.get(): if event.type == pygame.QUIT: is_running = False @@ -18,8 +23,8 @@ while is_running: particle.update(delta, particles) screen.fill((255, 255, 255)) - # for particle in particles: - # particle.draw_field_lines(screen) + for particle in particles: + particle.draw_field_lines(screen) for particle in particles: particle.draw_forces(screen) for particle in particles: diff --git a/particle.py b/particle.py index f5241c6..c63042e 100644 --- a/particle.py +++ b/particle.py @@ -9,7 +9,7 @@ class PointParticle: BLUE = (0, 153, 255) RED = (255, 43, 0) - field_line_colour = (12, 12, 12) + field_line_colour = (100, 100, 100) radius = 25 step_amount = 5 @@ -30,8 +30,7 @@ class PointParticle: self.field_line_angles = list(range(0, 360, math.ceil(360 / self.num_field_lines))) # List of angles self.field_lines = [[] for _ in range(self.num_field_lines)] - self.line_step = pygame.Vector2(self.step_amount, 0) if self.charge > 0 else pygame.Vector2(-self.step_amount, - 0) + self.line_step = pygame.Vector2(self.step_amount, 0) if self.charge > 0 else pygame.Vector2(-self.step_amount, 0) self.forces = [] self.net_electric_force = pygame.Vector2(0, 0) @@ -114,6 +113,9 @@ class PointParticle: -1 if particle.charge * self.charge > 0 else 1) self.forces.append(pygame.Vector2(electric_force * math.cos(angle), electric_force * math.sin(angle))) self.net_electric_force += self.forces[-1] + + self.position += self.net_electric_force * delta / 1000 * 2e33 + def draw_field_lines(self, surf): for line in self.field_lines: diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..90003ad --- /dev/null +++ b/readme.md @@ -0,0 +1,14 @@ +# Electric Dipole Simulation + +## Dependencies +(You might have to uninstall pygame if it is already installed) +```pip install pygame-ce library``` + +## how to run +run main.py + +## Controls +drag particles around to move them. + +## Extra +add more particles to particles list in main.py for more fun. diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..fe10527 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ + +pygame-ce \ No newline at end of file