Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

draw graphics with MIT scheme

I wish to plot graphically a function using MIT scheme. In the manual of scheme, there is a section called "Graphics" -- quote:

MIT Scheme has a simple two-dimensional line-graphics interface that is 
suitable for many graphics application.

If you experienced this, please help me by pasting a minimal working code (KISS principle) that works with MIT/scheme, and which plots something.

like image 478
alinsoar Avatar asked Nov 01 '12 01:11

alinsoar


4 Answers

It looks like this manual contains documentation of each individual function, but full out examples of every function do not appear to exist in any documentation online. The only way I was able to find working code was to Google the actual function names and arduously review each result for possible code samples.

Anyway, to satisfy your question and give you a simple example of how this library works, here is sample code.

    (let ((device (make-graphics-device (car (enumerate-graphics-types))))
          (x-start 0)
          (y-start 0)
          (x-end 5)
          (y-end 5))
      (graphics-draw-line device x-start y-start x-end y-end)
      (graphics-close device))

If you need more samples, let me know, but the code and docs should be enough to get you going.

like image 140
Alex V Avatar answered Nov 20 '22 04:11

Alex V


I'd just like to add that the code given by seisvelas (1/11/12), though correct, does not work on my 64-bit Linux system.
(Edited following alinsoar's observation) This is because the window is being closed within the scope of the let, so it actually works but it happens too fast to observe.

Try it like this:

(define device (make-graphics-device (car (enumerate-graphics-types))))
(graphics-draw-line device 0 0 5 5)
;; when you're good and ready
(graphics-close device)
like image 26
Alex Gian Avatar answered Nov 20 '22 04:11

Alex Gian


One thing to note for Mac OSX users is that you need to install and start XQuartz or (enumerate-graphics-types) will always be empty.

like image 3
dkinzer Avatar answered Nov 20 '22 04:11

dkinzer


I'm working on a plotting utility for windows users source

Its just built up from the primitives provided by "graphics" in mit-scheme but allows you to plot functions and vector fields.

like image 1
Anandamide Avatar answered Nov 20 '22 04:11

Anandamide