draw graphics with MIT scheme
Asked Answered
K

4

6

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.

Karlie answered 1/11, 2012 at 1:46 Comment(0)
A
6

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.

Allseed answered 1/11, 2012 at 7:37 Comment(2)
Thank you! (enumerate-graphics-types) returned for me (#[graphics-type 14 x]). And it WORKED. GOOD !Karlie
I like this answer, but note that doing all of this in a let block means that you won't actually see the graphics open, draw, and close. I prefer Alex Gian's answerFanniefannin
K
6

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)
Krypton answered 23/9, 2014 at 13:37 Comment(3)
the code of the graphics-device is hardware dependent, so no pretention to work for all computers. While the purpose of MIT scheme is not to develop a strong graphical interface, try instead racket's gui library, that has good graphical support. for me it works in MIT-scheme on thinkpad, 64 bits.Karlie
the scope with let ends after (graphics-close device), and has nothing to do with how graphics works.Karlie
This doesn't work for me; I'm using mit-scheme 10.1.10 on Debian buster 10 stable, and (enumerate-graphics-types) returns ().Clypeus
B
3

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.

Brandabrandais answered 20/2, 2015 at 1:15 Comment(0)
G
1

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.

Garb answered 12/11, 2015 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.