显示HN:一个交互式物理模拟器,在你的终端中拥有数千个球。
Show HN: An interactive physics simulator with 1000’s of balls, in your terminal

原始链接: https://github.com/minimaxir/ballin

## ballin: 一个终端物理模拟器 **ballin** 是一个用 Rust 构建的有趣、交互式物理模拟器,直接在你的终端中运行。它使用 Unicode Braille 字符可视化数千个弹跳的球,得益于 rapier 2D 引擎,实现了令人惊讶的逼真物理效果,帧率为 120+ FPS。 用户可以通过点击创建排斥爆发,使用数字键触发“喷泉”,以及生成新的球来与模拟进行交互。环境可以自定义,包括形状对象、可调节的重力和摩擦力,甚至颜色变化。创建的关卡可以保存并作为 JSON 文件共享。 **ballin** 在 Claude Opus 4.5 的协助下开发,优先考虑性能和可访问性。建议使用 Ghostty 等终端模拟器以获得最佳视觉效果,因为标准终端可能会限制帧速率。虽然为了防止崩溃,强制执行最多 15,000 个球的限制,但该模拟器在基于文本的界面限制内提供了一个独特而引人入胜的物理游乐场。 你可以在 GitHub 上找到二进制文件和源代码:[https://github.com/minimaxir/ballin](https://github.com/minimaxir/ballin)

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Show HN: 一个交互式物理模拟器,在你的终端里拥有数千个球 (github.com/minimaxir) 8 分,由 minimaxir 1小时前发布 | 隐藏 | 过去 | 收藏 | 2 评论 allenu 9分钟前 | 下一个 [–] 这个效果让我想起了 Future Crew 在 1992 年发布的经典 Fishtro 演示:https://www.youtube.com/watch?v=yUjRpLn2qWo 回复 nvader 21分钟前 | 上一个 [–] 这让我想到了我从未想过会想要的东西:终端里的等离子体乒乓球。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系方式 搜索:
相关文章

原文

Crates.io

A colorful interactive physics simulator with thousands of balls, but in your terminal!

ballin is a fun TUI app written in Rust that simulates thousands of logical balls, but despite the inherent character constraints of a terminal, you can see the realistic physics of the balls in action:

  • Extremely high performance using the rapier 2D Rust physics engine: it can handle physics actions on 10,000 balls at effective 120+ FPS!
  • Uses Braille Unicode to allow visualizing small, discrete balls.
  • Clicking the balls to cause a repulsing burst, or by using the geysers by pressing 1-6 or clicking them.
  • Clicking the top area of the canvas spawns more balls: clicking-and-holding spawns many balls.
  • Shake the entire canvas by resizing the terminal vertically, or by pressing the arrow keys to perform a pinball tilt.
  • Change the amount of gravity, friction, and the force of interactive effects to generate some very wacky interactions!
  • Add shape objects to obstruct the balls and create your own physics gym. You can even change the colors of the shapes to make it beautiful!
  • Save your constructed physics environment as a sharable JSON file!

Watch the color explosion in action!

ballin.mp4

Disclosure: This crate was developed with the assistance of Claude Opus 4.5 initially to answer the shower thought "would the Braille Unicode trick work to visually simulate complex ball physics in a terminal?" Opus 4.5 one-shot the problem, so I decided to further experiment to make it more fun and colorful. The full list of prompts used with Claude Code is present in PROMPTS.md.

The app binaries can be downloaded from the Releases page for your platform of choice, or by using the following terminal commands:

# macOS Apple Silicon
curl -sL https://github.com/minimaxir/ballin/releases/latest/download/ballin-macos-arm.tar.gz | tar xz

# macOS Intel
curl -sL https://github.com/minimaxir/ballin/releases/latest/download/ballin-macos-intel.tar.gz | tar xz

# Linux ARM64
curl -sL https://github.com/minimaxir/ballin/releases/latest/download/ballin-linux-arm64.tar.gz | tar xz

# Linux x64
curl -sL https://github.com/minimaxir/mballin/releases/latest/download/ballin-linux.tar.gz | tar xz

For Windows, download and unzip the binary from here.

If Rust is installed, you can install the crate directly via cargo:

It is VERY strongly recommended to use a terminal emulator such as Ghostty as normal terminals may have their frame rates capped at 30 FPS and the output looks choppy. The app looks comparatively poor in the native macOS Terminal.app, for example.

To run ballin: if you downloaded the binary, run it in the terminal with ./ballin. If you installed via Rust, run cargo run. The physics simulation will start with some shape objects randomly present to let the hilarity ensue immediately!

Press keys, click areas, see what happens? You can press ? for the full list of keyboard shortcuts.

Balls can be added to the machine by clicking the upper area: you can also hold Space to drop balls from all areas, or Shift+1/2/3/4/5/6 to drop balls in a specific section. You can also open Options to change the number of balls manually to a specified value, or Reset to return to the base number of balls.

For terminal compatability and accessibility reasons, Color Mode is disabled by default. To toggle it, just click the appropriately colorful Colors button (or press c) and the colors will appear! When triggering a geyser, it will color all affected balls the corresponding color.

Shapes can be inserted from the Shape menu. You can also click a Shape to select it: use the arrow keys to move a selected shape, press n/m to cycle through colors for the shape, or click-and-hold to drag the shape around.

Levels, which include options and shape objects, can be exported using Save and loaded using Load. The ballin level used in the video above is available in the level.json file.

You can also use the CLI arguments of --color to enable color by default, or --balls 10000 to increase the default number of starting balls.

  • The app intentionally uses the non-latest version of the rapier physics engine (0.31.0) because using latest version (0.32.0) frequently caused app panics in the constraints solver even at small numbers of balls. This is likely due to 0.32.0 changing the underlying linear algebra crates in the engine. Unfortunately, I don't know the engine well enough to construct a minimal reproducible test case to file as a regression bug report, or be able to isolate it as a side effect of a new API not well-known by Opus 4.5.
  • There is a hardcoded maximum of 15,000 balls in the simulator to avoid crashing on lower-specced hardware: on my MacBook Pro M3 Pro, any physics action drops the FPS below 30. Additionally, the terminal becomes too full of balls at standard terminal sizes.
  • It is possible for balls to go through line shapes if they are fast enough. This is expected: it's a phenomenon in physics engines known as tunneling, but the workaround of enabling Continuous Collision Detection (CDD) for every ball causes severe performance degradation with thousands of balls so it is not implemented.
  • The geyser feature is inspired by those weird mini-aquarium toys for kids at doctor's offices where pressing a button redirects the hydraulic force to disperse and scatter the colorful sparkles inside.
  • All colors within ballin are based on your defined terminal colors. The Ghostty terminal theme used in the example image/video is by David Crespo and is available here, although the examples use the Jetbrains Mono fontface instead.
  • ballin is the most perfect name for this crate and I will never name a Rust crate as good as this.

Max Woolf (@minimaxir)

Max's open-source projects are supported by his Patreon and GitHub Sponsors. If you found this project helpful, any monetary contributions to the Patreon are appreciated and will be put to good creative use.

MIT

联系我们 contact @ memedata.com