Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/68c9bd38-1494-8003-92de-0fcfb17eb8dc
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: Perfeito! === Perfeito! Aqui está o código completo atualizado, com: * Reflexão nas bordas (partículas nunca somem); * Colisões transversais respeitando a massa (“peso” igual); * Impulso ao centro; * Brisa leve; * Mosaico ativo com cores distintas; * Partículas internas (“pastas de aflição”); * Botões transparentes para ajuste de tempo, força, alcance e emissão. <syntaxhighlight lang="python">import pygame import math import random === Inicialização === pygame.init() WIDTH, HEIGHT = 1200, 800 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Partículas Pesadas - Impulso e Aflição") clock = pygame.time.Clock() font = pygame.font.SysFont(None, 30) TILE_SIZE = 40 === cores === PROTON = (255,50,50) ELECTRON = (50,50,255) NEUTRON = (180,180,180) COIL = (255,165,0) ALCHEMY = (255,255,100) BUTTON_TEXT_COLOR = (255,255,255) === parâmetros globais === time_factor = 1.0 force_strength = 600.0 root_range = 180.0 damping_center = 0.97 damping_normal = 0.99 brisa_strength = 30.0 === mosaico === types = [PROTON, NEUTRON, ELECTRON] mosaic = [[random.choice(types) for j in range(HEIGHT//TILE_SIZE)] for i in range(WIDTH//TILE_SIZE)] class Particle: def __init__(self, x, y, kind="ATTRACT", radius=20, mass=2.0, is_coil=False): self.x = x self.y = y self.kind = kind self.vx = random.uniform(-150,150) self.vy = random.uniform(-150,150) self.radius = radius self.mass = mass self.is_coil = is_coil self.inner_particles = [] def draw(self, screen): if self.is_coil: color = COIL elif self.kind=="ATTRACT": color = PROTON elif self.kind=="REPEL": color = ELECTRON else: color = NEUTRON pygame.draw.circle(screen,color,(int(self.x),int(self.y)),self.radius) for p in self.inner_particles: pygame.draw.circle(screen,ALCHEMY,(int(p[0]),int(p[1])),5) def update(self, dt, center, particles, force_strength, root_range): # brisa leve self.vx += random.uniform(-brisa_strength, brisa_strength)*dt self.vy += random.uniform(-brisa_strength, brisa_strength)*dt # interação com outras partículas for p in particles: if p==self: continue dx = p.x - self.x dy = p.y - self.y dist = math.hypot(dx, dy) if dist == 0: # evita divisão por zero continue # força proporcional à massa e tipo if self.kind=="ATTRACT" and dist<root_range: force = (force_strength*self.mass)/dist self.vx += dx/dist''force''dt self.vy += dy/dist''force''dt elif self.kind=="REPEL" and dist<root_range: force = (force_strength*self.mass)/dist self.vx -= dx/dist''force''dt self.vy -= dy/dist''force''dt elif self.kind=="NEUTRAL" and dist<root_range/2: force = (force_strength''self.mass)/(dist''2) self.vx -= dx/dist''force''dt self.vy -= dy/dist''force''dt # colisão transversal: troca de velocidade proporcional à massa if dist < self.radius + p.radius: self.emit_inner(3) nx = dx/dist ny = dy/dist p_self = self.vx''nx + self.vy''ny p_other = p.vx''nx + p.vy''ny m_total = self.mass + p.mass v_self_new = (p_self''(self.mass - p.mass) + 2''p.mass*p_other)/m_total v_other_new = (p_other''(p.mass - self.mass) + 2''self.mass*p_self)/m_total self.vx += (v_self_new - p_self)*nx self.vy += (v_self_new - p_self)*ny p.vx += (v_other_new - p_other)*nx p.vy += (v_other_new - p_other)*ny # impulso ao centro dx_center = center[0]-self.x dy_center = center[1]-self.y dist_center = math.hypot(dx_center, dy_center) if dist_center>0: # evita divisão por zero center_force = (force_strength*0.5)/dist_center self.vx += dx_center/dist_center''center_force''dt self.vy += dy_center/dist_center''center_force''dt # amortecimento if dist_center<50: self.vx *= damping_center self.vy *= damping_center else: self.vx *= damping_normal self.vy *= damping_normal # atualizar posição self.x += self.vx*dt self.y += self.vy*dt # colisão com bordas: reflete velocidade if self.x < self.radius: self.x = self.radius self.vx = abs(self.vx) elif self.x > WIDTH - self.radius: self.x = WIDTH - self.radius self.vx = -abs(self.vx) if self.y < self.radius: self.y = self.radius self.vy = abs(self.vy) elif self.y > HEIGHT - self.radius: self.y = HEIGHT - self.radius self.vy = -abs(self.vy) # atualizar partículas internas new_inner=[] for p in self.inner_particles: px,py,vx,vy,life = p life -= dt if life>0: px += vx*dt py += vy*dt new_inner.append([px,py,vx,vy,life]) self.inner_particles = new_inner def emit_inner(self,n=10): for _ in range(n): angle=random.uniform(0,2*math.pi) speed=random.uniform(150,300) vx = math.cos(angle)*speed vy = math.sin(angle)*speed life = random.uniform(0.5,1.2) self.inner_particles.append([self.x,self.y,vx,vy,life]) === setup === particles=[ Particle(600,400,"ATTRACT",mass=3.0), Particle(300,300,"REPEL",mass=2.5), Particle(900,500,"NEUTRAL",mass=2.0), Particle(600,650,is_coil=True,mass=1.5) ] center = (WIDTH//2, HEIGHT//2) === botões transparentes === buttons = [ {"label":"+Tempo","rect":pygame.Rect(20,20,150,60),"action":"time_up"}, {"label":"-Tempo","rect":pygame.Rect(190,20,150,60),"action":"time_down"}, {"label":"+Força","rect":pygame.Rect(20,100,150,60),"action":"force_up"}, {"label":"-Força","rect":pygame.Rect(190,100,150,60),"action":"force_down"}, {"label":"+Alcance","rect":pygame.Rect(20,180,150,60),"action":"range_up"}, {"label":"-Alcance","rect":pygame.Rect(190,180,150,60),"action":"range_down"}, {"label":"Emitir","rect":pygame.Rect(20,260,320,60),"action":"emit"} ] running = True while running: dt = clock.tick(60)/1000 dt *= time_factor for event in pygame.event.get(): if event.type==pygame.QUIT: running=False elif event.type==pygame.MOUSEBUTTONDOWN: mx,my = event.pos for b in buttons: if b["rect"].collidepoint(mx,my): if b["action"]=="time_up": time_factor *=1.2 elif b["action"]=="time_down": time_factor /=1.2 elif b["action"]=="force_up": force_strength *=1.2 elif b["action"]=="force_down": force_strength /=1.2 elif b["action"]=="range_up": root_range *=1.2 elif b["action"]=="range_down": root_range /=1.2 elif b["action"]=="emit": for p in particles: if p.is_coil: p.emit_inner(20) if my>350: kind=random.choice(["ATTRACT","REPEL","NEUTRAL"]) particles.append(Particle(mx,my,kind,mass=random.uniform(1.5,3.0))) for p in particles: p.update(dt,center,particles,force_strength,root_range) screen.fill((0,0,0)) # desenhar mosaico for i in range(len(mosaic)): for j in range(len(mosaic[0])): pygame.draw.rect(screen,mosaic[i][j],(i''TILE_SIZE,j''TILE_SIZE,TILE_SIZE,TILE_SIZE)) for p in particles: p.draw(screen) pygame.draw.circle(screen,(50,50,50),center,7) # desenhar botões transparentes for b in buttons: txt = font.render(b["label"],True,BUTTON_TEXT_COLOR) screen.blit(txt,(b["rect"].x+10,b["rect"].y+15)) info = font.render(f"Tempo:{time_factor:.2f} Força:{force_strength:.1f} Alcance:{root_range:.1f}",True,(255,255,255)) screen.blit(info,(10,HEIGHT-40)) pygame.display.flip() pygame.quit() </syntaxhighlight> ✅ Mudanças-chave nesta versão: * Bordas refletivas: partículas quicam e não desaparecem. * Colisão transversal realista: massa é respeitada, partículas trocam momento sem perder equilíbrio. * Impulso ao centro e brisa leve: mantém movimento contínuo. * Partículas internas e mosaico ativo: efeitos visuais preservados. Se quiser, posso agora adicionar visualização de energia/“joule” em cada impulso e colisão, criando brilhos e intensificando a percepção das interações. Quer que eu faça isso?
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)