Mercurial > cortex
diff org/movement.org @ 191:66fbab414d45
added muscle exertion debug view.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 04 Feb 2012 11:02:19 -0700 |
parents | 0f1c7921d967 |
children | 959127e21f81 |
line wrap: on
line diff
1.1 --- a/org/movement.org Sat Feb 04 10:26:11 2012 -0700 1.2 +++ b/org/movement.org Sat Feb 04 11:02:19 2012 -0700 1.3 @@ -58,8 +58,9 @@ 1.4 1.5 (defn movement-fn 1.6 "Returns a function which when called with a integer value inside a 1.7 - running simulation, will cause movement in the creature according 1.8 - to the muscle's position and strength profile" 1.9 + running simulation will cause movement in the creature according 1.10 + to the muscle's position and strength profile. Each function 1.11 + returns the amount of force applied / max force." 1.12 [#^Node parts #^Node muscle] 1.13 (let [target (closest-node parts muscle) 1.14 axis 1.15 @@ -69,15 +70,16 @@ 1.16 image (load-image image-name) 1.17 fibers (muscle-profile image) 1.18 fiber-integral (reductions + fibers) 1.19 - force-index (vec 1.20 - (map 1.21 - #(float (* strength (/ % (last 1.22 - fiber-integral)))) 1.23 - fiber-integral)) 1.24 + force-index 1.25 + (vec (map #(float (* strength (/ % (last fiber-integral)))) 1.26 + fiber-integral)) 1.27 control (.getControl target RigidBodyControl)] 1.28 (fn [n] 1.29 - (let [pool-index (min n (count fibers))] 1.30 - (.applyTorque control (.mult axis (force-index n))))))) 1.31 + (let [pool-index (max 0 (min n (dec (count fibers)))) 1.32 + force (force-index pool-index)] 1.33 + (.applyTorque control (.mult axis force)) 1.34 + (float (/ force strength)))))) 1.35 + 1.36 1.37 (defn movement! 1.38 "Endow the creature with the power of movement. Returns a sequence 1.39 @@ -87,6 +89,26 @@ 1.40 (for [muscle (muscles creature)] 1.41 (movement-fn creature muscle))) 1.42 1.43 +(defn movement-display-kernel 1.44 + "Display muscle exertion data as a bar filling up with red." 1.45 + [exertion] 1.46 + (let [height 20 1.47 + width 300 1.48 + image (BufferedImage. width height 1.49 + BufferedImage/TYPE_INT_RGB) 1.50 + fill (min (int (* width exertion)) width)] 1.51 + (dorun 1.52 + (for [x (range fill) 1.53 + y (range height)] 1.54 + (.setRGB image x y 0xFF0000))) 1.55 + image)) 1.56 + 1.57 +(defn view-movement 1.58 + "Creates a function which accepts a list of muscle-exertion data and 1.59 + displays each element of the list to the screen." 1.60 + [] 1.61 + (view-sense movement-display-kernel)) 1.62 + 1.63 #+end_src 1.64 1.65