From 77a9705552f93f0c47f26b9b01117070c0ca6c2e Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Sun, 26 Jun 2016 10:32:14 +0200 Subject: [PATCH] Function for update one particle --- examples/particle-system.scm | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/particle-system.scm b/examples/particle-system.scm index 2b2c1b5..a0d659a 100644 --- a/examples/particle-system.scm +++ b/examples/particle-system.scm @@ -39,26 +39,26 @@ (draw-quad (list x y z) #:color (list r g b)))))) particles)) +(define (update-particle particle) + (match particle + ((x y z vx vy vz) + (let* ((distance-squared (+ (* x x) (* y y) (* z z))) + (distance (sqrt distance-squared)) + (F (/ -200 distance-squared)) + (ax (* F (/ x distance))) + (ay (* F (/ y distance))) + (az (* F (/ z distance)))) + (list (+ x (* vx dt) (* ax half-dt-squared)) + (+ y (* vy dt) (* ay half-dt-squared)) + (+ z (* vz dt) (* az half-dt-squared)) + (+ vx (* ax dt)) + (+ vy (* ay dt)) + (+ vz (* az dt))))))) + (define (update-particles dt) (let ((half-dt-squared (* 0.5 dt dt))) (set! *particles* - (map - (lambda (particle) - (match particle - ((x y z vx vy vz) - (let* ((distance-squared (+ (* x x) (* y y) (* z z))) - (distance (sqrt distance-squared)) - (F (/ -200 distance-squared)) - (ax (* F (/ x distance))) - (ay (* F (/ y distance))) - (az (* F (/ z distance)))) - (list (+ x (* vx dt) (* ax half-dt-squared)) - (+ y (* vy dt) (* ay half-dt-squared)) - (+ z (* vz dt) (* az half-dt-squared)) - (+ vx (* ax dt)) - (+ vy (* ay dt)) - (+ vz (* az dt))))))) - *particles*)))) + (map update-particle *particles*)))) (define (prepare-particles n) (cond ((= n 0) -- 2.39.2