import pygame
+from particle import PointParticle
+
SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Electric Dipoles")
+is_running = True
+clock = pygame.Clock()
+delta = 0
+
+particles = [PointParticle((SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2))]
+
+while is_running:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ is_running = False
+
+ for particle in particles:
+ particle.update(delta)
+
+ screen.fill((255, 255, 255))
+ for particle in particles:
+ particle.draw(screen)
+
+ pygame.display.flip()
+ delta = clock.tick()
--- /dev/null
+import pygame
+
+
+class PointParticle:
+
+ def __init__(self, position, charge=1.6e-19):
+ self.position = pygame.Vector2(position)
+ self.mouse_offset = pygame.Vector2(0, 0)
+ self.charge = charge
+ self.radius = 50
+ self.dragging = False
+ self.colour = (255, 0, 0) if self.charge < 0 else (0, 0, 255)
+
+ def update(self, delta):
+ if pygame.mouse.get_pressed(3)[0]:
+ if not self.dragging and self.position.distance_to(pygame.mouse.get_pos()) < self.radius:
+ self.mouse_offset = pygame.Vector2(pygame.mouse.get_pos()) - self.position
+ self.dragging = True
+ if self.dragging:
+ self.position = pygame.Vector2(pygame.mouse.get_pos()) - self.mouse_offset
+ elif self.dragging:
+ self.dragging = False
+
+ def draw(self, surf):
+ pygame.draw.circle(surf, self.colour, self.position, self.radius)
+ pygame.draw.circle(surf, (0, 0, 0), self.position, self.radius, 3)