import pygame import random Inicializar Pygame pygame.init() Dimensiones de la pantalla…
- User
import pygame import random
Inicializar Pygame
pygame.init()
Dimensiones de la pantalla
WIDTH, HEIGHT = 800, 600 SCREEN = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Simulación del Bosón de Higgs")
Definir colores
WHITE = (255, 255, 255) BLUE = (50, 150, 255) RED = (255, 100, 100) GREEN = (100, 255, 100)
Constantes de la simulación
PARTICLE_COUNT = 100 # Aumentamos el número de partículas MAX_SPEED = 5 HIGGS_INTERACTION_FACTOR = 0.9 # Factor de reducción de velocidad en el campo de Higgs OUTSIDE_INTERACTION_FACTOR = 1.02 # Factor de aumento de velocidad fuera del campo de Higgs
Clase Partícula
class Particle: def init(self): # Posición y velocidad utilizando vectores self.pos = pygame.Vector2(random.uniform(0, WIDTH), random.uniform(0, HEIGHT)) angle = random.uniform(0, 360) speed = random.uniform(2, MAX_SPEED) self.vel = pygame.Vector2(speed, 0).rotate(angle) self.mass = 1 # Masa inicial self.size = 5 # Tamaño inicial self.color = BLUE # Color inicial
codedef update(self, higgs_field_rect): # Verificar si la partícula está en el campo de Higgs if higgs_field_rect.collidepoint(self.pos): # Interacción con el campo de Higgs self.mass = 5 self.size = 10 self.color = RED self.vel *= HIGGS_INTERACTION_FACTOR # Reducir la velocidad else: # Sin interacción self.mass = 1 self.size = 5 self.color = BLUE self.vel *= OUTSIDE_INTERACTION_FACTOR # Aumentar ligeramente la velocidad # Limitar la velocidad máxima if self.vel.length() > MAX_SPEED: self.vel.scale_to_length(MAX_SPEED) # Actualizar posición self.pos += self.vel # Manejar los bordes de la pantalla con rebote if self.pos.x <= 0 or self.pos.x >= WIDTH: self.vel.x *= -1 self.pos.x = max(0, min(self.pos.x, WIDTH)) if self.pos.y <= 0 or self.pos.y >= HEIGHT: self.vel.y *= -1 self.pos.y = max(0, min(self.pos.y, HEIGHT)) def draw(self, screen): pygame.draw.circle(screen, self.color, (int(self.pos.x), int(self.pos.y)), self.size) - Assistant