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! Pelo que você descreveu, você quer controle total sobre o tempo e a força de interação, assim como a “abertura” das raízes (atração/repulsão) para as partículas. Podemos implementar isso permitindo: # Aceleração de tempo variável: o usuário controla a velocidade global do sistema. # Força de interação ajustável: o usuário define o quanto as partículas se atraem ou se repelem. # Controle da “abertura das raízes”: determina o alcance da força (distância máxima de atração ou repulsão). Vou criar um código completo que permite alterar esses parâmetros dinamicamente via teclado: * Setas para ajustar a força das raízes. * W/S para aumentar/diminuir a aceleração do tempo. * A/R para aumentar/diminuir o alcance das interações. <syntaxhighlight lang="python">import pygame import math import random pygame.init() WIDTH, HEIGHT = 800, 600 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Cúpulas Químicas com Controle Dinâmico") clock = pygame.time.Clock() TILE_SIZE = 40 === cores base === ATTRACT = (255, 50, 50) REPEL = (50, 50, 255) NEUTRAL = (180,180,180) COIL = (255,165,0) ALCHEMY = (255,255,100) === mosaico === mosaic = [] for i in range(WIDTH // TILE_SIZE): row = [] for j in range(HEIGHT // TILE_SIZE): choices = random.choices([ATTRACT, REPEL, NEUTRAL], [0.3,0.3,0.4], k=random.choice([1,2])) row.append(choices) mosaic.append(row) class Particle: def __init__(self, x, y, kind="ATTRACT", mass=1, radius=14, 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.mass = mass self.radius = radius self.is_coil = is_coil self.inner_particles = [] def draw(self, screen): if self.is_coil: color = COIL elif self.kind=="ATTRACT": color = ATTRACT elif self.kind=="REPEL": color = REPEL else: color = NEUTRAL 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])),3) def update(self, dt, center, particles, force_strength, root_range): 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: dist=0.1 # Atração/Repulsão controlável if self.kind=="ATTRACT" and dist<root_range: force = force_strength/dist self.vx += dx/dist''force''dt self.vy += dy/dist''force''dt elif self.kind=="REPEL" and dist<root_range: force = force_strength/(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/(dist*2) self.vx -= dx/dist''force''dt self.vy -= dy/dist''force''dt # Centro como jockey dx_center = center[0]-self.x dy_center = center[1]-self.y dist_center = math.hypot(dx_center,dy_center) if dist_center<30: self.vx *= 0.8 self.vy *= 0.8 else: self.vx *= 0.9 self.vy *= 0.9 # Atualizar posição self.x += self.vx*dt self.y += self.vy*dt self.x = max(self.radius,min(WIDTH-self.radius,self.x)) self.y = max(self.radius,min(HEIGHT-self.radius,self.y)) # 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(200,400) 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(400,300,"ATTRACT"), Particle(200,200,"REPEL"), Particle(600,400,"NEUTRAL"), Particle(400,500,is_coil=True) ] center = (WIDTH//2, HEIGHT//2) time_factor = 1.0 # aceleração de tempo inicial force_strength = 400.0 # força inicial das raízes root_range = 150 # alcance inicial das raízes 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: x,y=pygame.mouse.get_pos() kind=random.choice(["ATTRACT","REPEL","NEUTRAL"]) particles.append(Particle(x,y,kind)) elif event.type==pygame.KEYDOWN: if event.key==pygame.K_SPACE: for p in particles: if p.is_coil: p.emit_inner(20) # ajustar tempo elif event.key==pygame.K_w: time_factor *= 1.2 elif event.key==pygame.K_s: time_factor /= 1.2 # ajustar força elif event.key==pygame.K_UP: force_strength *= 1.2 elif event.key==pygame.K_DOWN: force_strength /= 1.2 # ajustar alcance das raízes elif event.key==pygame.K_a: root_range *= 1.2 elif event.key==pygame.K_d: root_range /= 1.2 for p in particles: p.update(dt,center,particles,force_strength,root_range) # Desenhar mosaico for i in range(len(mosaic)): for j in range(len(mosaic[0])): cell = mosaic[i][j] if len(cell)==1: color = cell[0] else: color = tuple(min(255,sum(c)//len(c)) for c in zip(*cell)) pygame.draw.rect(screen,color,(i''TILE_SIZE,j''TILE_SIZE,TILE_SIZE,TILE_SIZE)) # Desenhar partículas for p in particles: p.draw(screen) # Centro (jockey) pygame.draw.circle(screen,(50,50,50),center,5) pygame.display.flip() pygame.quit() </syntaxhighlight> ===== 1. Controle de aceleração de tempo: - W aumenta, S diminui. ===== # Controle da força das raízes (atração/repulsão): - UP aumenta, DOWN diminui. # Controle do alcance da interação: - A aumenta, D diminui. # Cúpulas químicas dinâmicas continuam com cores distintas e partículas internas. # Centro funciona como jockey, sem afetar a fricção ou dispersão. Se você quiser, posso adicionar uma interface visual mínima no canto da tela mostrando tempo, força e alcance atuais, para acompanhar em tempo real enquanto interage com o sistema. 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)