From 1056081932314dbf339c97d6a7bda4fb927d4e39 Mon Sep 17 00:00:00 2001 From: Dimitri Lozeve Date: Tue, 18 Jul 2017 18:12:03 +0200 Subject: [PATCH] Update position and speed of all bodies --- src/Lib.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Lib.hs b/src/Lib.hs index b5bfaef..8e7b63b 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -70,7 +70,17 @@ update dt (Body m pos speed) neighbours = newspeed = speed + dt *^ accel newpos = pos + dt *^ P newspeed - +-- Update all bodies with a timestep dt +updateAll :: Double -> [Body] -> [Body] +updateAll dt bodies = aux [] [] bodies + where + -- Cycles through all bodies, updates each one and stores it in + -- res. Each body already updated is moved to prev. + aux res prev [] = res + aux res prev (b:next) = + aux (newb:res) (b:prev) next + where newb = update dt b $ prev ++ next + -------------------------------------------------------------------------------- -- EXAMPLES --------------------------------------------------------------------------------