summaryrefslogtreecommitdiff
path: root/sly/math.scm
diff options
context:
space:
mode:
authorJordan Russell <jordan.likes.curry@gmail.com>2014-07-10 21:29:02 -0700
committerDavid Thompson <dthompson2@worcester.edu>2014-08-01 07:19:09 -0400
commit1a8ffb0ea7233c55148118c09a7b281673df86c2 (patch)
tree335d6c48f74f06ce592f953dc6c99db7e6c4c29b /sly/math.scm
parent5926500a1cbf7d809d1f62ec6710bf6b6fe403e7 (diff)
Add joystick module.
* sly/joystick.scm: New file. * examples/joystick.scm: New file. * Makefile.am (SOURCES): Add sly/joystick.scm. * TODO.org (Input): Mark as 'done'. * sly/math.scm (linear-scale): New procedure.
Diffstat (limited to 'sly/math.scm')
-rw-r--r--sly/math.scm10
1 files changed, 9 insertions, 1 deletions
diff --git a/sly/math.scm b/sly/math.scm
index 073a399..c25e24d 100644
--- a/sly/math.scm
+++ b/sly/math.scm
@@ -1,5 +1,6 @@
;;; Sly
;;; Copyright (C) 2013, 2014 David Thompson <dthompson2@worcester.edu>
+;;; Copyright (C) 2014 Jordan Russell <jordan.likes.curry@gmail.com>
;;;
;;; This program is free software: you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License as
@@ -29,7 +30,8 @@
cos-degrees
tan-degrees
atan-degrees
- clamp))
+ clamp
+ linear-scale))
;; Dave was editing this module on Pi Approximation Day.
;;
@@ -89,3 +91,9 @@ actually less than MAX."
(cond ((< x min) min)
((> x max) max)
(else x)))
+
+(define (linear-scale min max a b val)
+ "Map a VAL in the range [MIN,MAX] to numbers in [A,B]"
+ (+ a
+ (/ (* (- b a) (- val min))
+ (- max min))))