Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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)

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.

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top