plot.body.scm 757 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env scheme-r7rs
  2. ; This is a library for plotting a function with text
  3. (define (plot f y-min y-max x-min x-max text-height text-width)
  4. (define delta-x (/ (- x-max x-min) text-width))
  5. (define delta-y (/ (- y-max y-min) text-height))
  6. (let row-loop ((row 0)
  7. (y y-max))
  8. (if (< row text-height)
  9. (let col-loop ((col 0)
  10. (x x-min))
  11. (if (< col text-width)
  12. (begin
  13. (if (< y (f x))
  14. (display "*")
  15. (display " "))
  16. (col-loop (+ col 1)
  17. (+ x delta-x)))
  18. (begin
  19. (newline)
  20. (row-loop (+ row 1)
  21. (- y delta-y))))))))