# bowntz: audio-visual pseudo-physical simulation of colliding circles

[ demo, gpl, program ] [ Propose Tags ]
Versions 0, 1 base (>=4.8 && <4.10), containers (==0.5.*), GLUT (==2.7.*), hosc (==0.15.*), hsc3 (==0.15.*), random (==1.1.*) [details] GPL-3.0-only 2010,2013,2015,2016 Claude Heiland-Allen Claude Heiland-Allen claude@mathr.co.uk Demo https://code.mathr.co.uk/bowntz head: git clone https://code.mathr.co.uk/bowntz.gitthis: git clone https://code.mathr.co.uk/bowntz.git(tag v1) by ClaudeHeilandAllen at Sat Jun 18 00:10:13 UTC 2016 NixOS:1 bowntz 592 total (11 in the last 30 days) (no votes yet) [estimated by rule of succession] λ λ λ Docs not available Last success reported on 2016-10-27 Hackage Matrix CI

#### Maintainer's Corner

For package maintainers and hackage trustees

[back to package description]
Bowntz -- an audio-visual pseudo-physical simulation of colliding circles

Build
-----

$ghc -O2 -Wall --make bowntz.hs Bowntz requires hsc3 >= 0.8 (newer than Hackage, as of 2010-03-12). Usage -----$ scsynth -u 57110 &
-- wait for scsynth to start, connect its JACK ports --
\$ ./bowntz

Bowntz requires a "clean" SC3 server to be running on its usual port.
Bowntz leaves this SC3 server in an "unclean" state when it exits.

This situation is far from ideal, but it's the current state of the code.

Notes
-----

The world is a collection of N circles which each move at a constant speed
in a straight line (in the absence of collisions).  Given two such circles
it is possible to calculate the precise time of their next collision.  For
N circles, O(N^2) such "next" collisions may occur.

Pick the soonest next collision between circles A and B.  This collision
will change the velocities of A and B, but no other circle.  Update the
collection of collisions, by removing all the other "next" collisions
involving either A or B, and computing the new collisions of A and B with
all the other circles (O(N) collisions).  For maintaining a consistent
time-base for all circles in the world, it makes sense to advance in a
straight line each circle to its position at the time of the collision.

Given a world at time T, to find the world at time T+dT simply step
through the future collisions one by one until the soonest collision is
after T+dT, at which point one can just advance the circles in straight
lines to T+dT.

T       T+1      T+2      T+3      T+4      T+5      T+6      T+7
... |        |        |        |        |        |        |        | ...
----*---*---*---------*---------------**-*--*-*-------*------*--

Care needs to be taken in case of numerical imprecision: one can get an
infinite number of collisions without time increasing.

To do
-----

General code clean-up and documentation.

Optimizations based on collision possibility tree, example:

A               7 possible
|               A~*~B
+---B           A~*~E    5 impossible
|   +---C       B~*~C    !A~*~C
|   +---D       B~*~D    !A~*~D
|               C~*~D    !C~*~F
+---E           B~*~E    !D~*~F
+---F       E~*~F    !A~*~F

data Node = Node ID [Node]
possibles n@(Node _ ns) = possible n map ns ++ liftM2 possible ns

Infinite zoom into circles within circles within circles within circles?
When (if ever) would it be safe to prune "outside"?

Some kind of loop where circles contain themselves (I did try this in
another unreleased version but it resulted in hyperexponential kinetic
energy increase, which naturally caused problems).

Non-flat space.

Angular momentum affecting collisions.

Remove all sources of non-determinism to enable two-pass rendering:
1 pass to record audio from SC3    in realtime
2 pass to record video from OpenGL in non-realtime
Or just record ball positions in the first pass for later drawing (because
callback races and/or timing instability might affect the reproducibility
unless very precise care is taken at all stages..)

Interactivity.

More impressive audio-visuals.

Won't
-----

Anything other than circles (ok, maybe infinite lines would be ok, but
asymmetry with angular momentum would quickly make collision detection
get horribly complicated).

Legal
-----

This program is free software: you can redistribute it and/or modify