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! Então precisamos adicionar dois ajustes importantes: # Bloquear partículas nas bordas → ao invés de apenas limitar a posição, vamos refletir a velocidade nas laterais, fazendo-as “quicar” e nunca sumirem. # Manter massa igual nas colisões transversais → quando partículas se tocam, elas trocam momento proporcional à massa, mantendo o mesmo peso, sem que uma acelere demais ou desapareça. Vou reescrever o trecho de atualização da partícula para incluir essas duas regras, mantendo todo o resto da simulação intacta: <syntaxhighlight lang="python">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: 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) # simples colisão elástica 1D aproximada 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: 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 </syntaxhighlight> ✅ O que mudou: # Reflexão nas bordas: partículas nunca somem, quicam suavemente. # Colisão transversal realista: troca de velocidades respeita a massa das partículas, mantendo o “peso” igual. # Mantidas partículas internas, impulso ao centro, brisa e mosaico ativo. Se quiser, posso integrar essa atualização no código completo pronto para rodar, com todas as funcionalidades anteriores e agora evitando sumiço e mantendo massa nas colisõ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)