LLM Test Prompts

All prompts › Simulations & physics

Pouring water from a tilting cup: particle fluid in pygame

Simulations & physicshardbuild testPrompt in ChinesePythonpygamephysicsChinese

What it tests: A 2D particle fluid with hand-written collisions against a rotating container: leak-proof segment joints, restitution, particle repulsion and a coordinate transform for the tilting cup, specified step by step in Chinese.

Prompt length: 1,236 characters, roughly 820 tokens (estimate).

Prompt
请使用Python和pygame库,创建一个二维流体模拟程序。该程序需要模拟液体(由大量粒子代表)在重力作用下从一个正在倾斜的杯子中倒出的过程。

## 核心要求:

### 创建Pygame环境:

初始化一个pygame窗口,尺寸建议为 1920x1080像素。
设置一个主循环来处理事件、更新物理状态和渲染画面。
背景色设置为白色。

### 定义杯子容器:

杯子是二维的,由几条线段构成一个容器形状。杯口为空,向上放置。你可以用一个顶点列表来定义其形状,例如 [(x1, y1), (x2, y2), ...]。
初始状态下,杯子应竖直立在屏幕中间。
杯子的线条应能被渲染出来,颜色为黑色。

### 创建粒子系统:

液体由大量的粒子(例如400个)来表示。
每个粒子都是一个小圆圈,拥有以下属性:
- 位置 (x, y)
- 速度 (vx, vy)
- 直径 (e.g., 4 像素)
- 颜色 (e.g., 蓝色)
  
建议创建一个Particle类来管理这些属性。
初始时,所有粒子在杯子上方的位置逐步生成,让粒子全部流入杯子内部。


### 实现物理模拟:

#### 重力: 
在每个时间步(frame),对所有粒子施加一个恒定的向下的加速度(例如 g = 0.1)。

#### 与容器的碰撞:
实现粒子与构成杯子的线段之间的碰撞检测。
需要防止粒子从线段之间的连接点漏出去。
当粒子撞击墙壁时,其速度应该被反弹。为了模拟能量损失,反弹后的速度应该乘以一个小于1的恢复系数(e.g., 0.7)。

#### 粒子间的相互作用 (简化流体行为):
这是模拟的关键。为了防止粒子不自然地聚集或重叠,实现一个简单的排斥力。
当两个粒子的距离小于它们半径之和的某个阈值时,给它们施加一个微小的、沿两者中心连线方向向外的力。这可以简单地通过直接调整它们的位置或速度来实现,将它们轻微推开。

#### 运动更新: 
使用欧拉积分法(Euler integration)来更新每个粒子的位置:
velocity += acceleration * dt
position += velocity * dt
(为了简化,你可以假设 dt=1,并将加速度直接加到速度上)。

#### 屏幕底部:
粒子落到屏幕底部而不是掉出去.

### 实现动画效果:

生成粒子:先在杯子上方生成粒子,全部流入杯中。
杯子倾倒: 然后,杯子需要随时间缓慢旋转。
让杯子围绕其中心的一个点进行旋转。
旋转角度可以从0度缓慢增加到约135度,模拟倒水的过程。

### 代码结构:
- 请使用面向对象的方法,例如创建Particle类和Flask类。
- 在代码的关键部分添加注释,特别是物理计算(重力、碰撞、粒子间作用力)和坐标变换(杯子旋转)的部分。
- 注意需要先绘制杯子然后再绘制粒子,以免粒子直接掉下去。
- 代码中请全部使用英文。所有代码放在同一个 py 文件里
English translation (English summary translation by BranoLabs (CC BY-NC-SA 4.0). Paste the Chinese original to stay comparable with KCORES results.)
Translation
Using Python and pygame, write a 2D fluid simulation. About 400 particles fall from above into an upright cup made of line segments in the middle of a white 1920×1080 window; then the cup slowly rotates about its centre from 0° to about 135° and the liquid pours out. Particles have position, velocity, a 4 px diameter and a blue colour (use a Particle class and a Flask class). Physics: constant gravity (e.g. g = 0.1); particle-segment collisions that must not leak through the joints between segments, with velocity multiplied by a restitution below 1 (e.g. 0.7); a simple repulsion between particles closer than a threshold; Euler integration (dt = 1 is fine); particles stop at the bottom of the screen instead of falling out. Comment the physics and the rotation transform, draw the cup before the particles, write all code and comments in English, and keep everything in one .py file.

How to grade it

Checklist from the prompt itself: one .py file with English code; a white 1920×1080 pygame window; a black cup drawn from a vertex list; particles spawn above and all flow into the cup first; gravity, restitution of about 0.7, and repulsion so particles don't collapse into one point; no leaks at segment joints (watch the corners closely while the cup tilts); the cup rotates about its own centre to about 135°; particles pile up at the bottom of the screen.

Scorecard tick what the model got right: 0/8

Runs in your browser; nothing is saved or sent.

0/8

Where models usually fail

Particles tunnel through the walls or leak at the joints once the cup rotates (collision done against the unrotated shape); all particles collapse into a dense blob; the cup rotates around the window origin instead of its centre.

Running it

KCORES runs each model 3 times, keeps the best run and scores it visually at 2K full screen. Temperature 0 makes your own runs comparable.

Source

Testing a local model? Check first whether it fits your hardware with Can I run this LLM?

More in Simulations & physics