Please write a simple particle system in python, using dataclasses.
- User
Please write a simple particle system in python, using dataclasses.
Assistant
Here's a simple particle system in Python using dataclasses:
from dataclasses import dataclass from random import random, uniform from typing import List @dataclass class Particle: x: float y: float vx: float = 0 vy: float = 0 def update(self): self.x += self.vx self.y += self.vy @dataclass class ParticleSystem: particles: List[Particle] gravity: float = 0.1 def update(self): for p in self.particles: p.update() p.vy -= self.gravity if p.y < 0: p.vy *= -0.5 p.y = 0 def add_particle(self): self.particles.append(Particle( x=uniform(0, 1), y=1, vx=uniform(-0.1, 0.1), vy=random() * -1 )) system = ParticleSystem(particles=[]) for i in range(100): system.add_particle() while True: system.update()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.