Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nathan Hamblen
committed
Apr 10, 2010
1 parent
07db921
commit 1c87764
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def plot(minX: Int, maxX: Int) = { | ||
val rangeX = maxX - minX | ||
lazy val inputs = (0 to width) map { px => | ||
(px, minX + (px.toFloat / width * rangeX).toInt) | ||
} | ||
{ f: (Int => Int) => | ||
val values = inputs map { case (px, x) => (px, x, f(x)) } | ||
val (headPX, headX, headY) = values.head | ||
val (minY, maxY) = ((headX, headY) /: values.tail) { | ||
case ((max, min), (px, x, y)) => | ||
(if (y > max) y else max, if (y < min) y else min) | ||
} | ||
val rangeY = maxY - minY | ||
val points = values map { case (px, x, y) => | ||
(px, ((y - minY).toFloat / rangeY * height).toInt) | ||
} | ||
for ( (x, y) <- points ) point(x, y) | ||
} | ||
} | ||
val centplot = plot(-100, 100) | ||
|
||
size(500, 500) | ||
|
||
def draw { | ||
centplot { x => x } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters