Arc Forumnew | comments | leaders | submitlogin
Basic Graphics?
7 points by tokipin 6112 days ago | 3 comments
I find I learn languages faster if I'm able to make visual programs and tools in them. My "Hello World" is the Sierpinski triangle. I skipped C++ and grew up on Java because drawing was much easier in that language.

So my question is: How can I get basic graphics (point, circle, etc) output from Arc? I guess finding out how it's done in MzScheme would be an obvious approach, but I'm curious if anyone is already familiar with some details that might make my life easier.

Thanks in advance.



7 points by kens 6112 days ago | link

Here's one way to do graphics in Arc using DrScheme and MrEd.

I loaded "as.scm" into DrScheme.

I added simple make-canvas and draw-point commands to the as.scm code to use the MrEd Graphical Toolbox, and exported these commands to Arc.

I wrote a simple Arc function to draw the Sierpinski triangle using these graphics functions.

Specifically, I added the following code to as.scm.

  (define (make-canvas w h)
    (define frame (instantiate frame% ("Gasket by Ken Shirriff") (width w) (height h)))
    (define canvas (instantiate canvas% (frame)))
    (define dc (send canvas get-dc))
    (send frame show #t)
    dc ;; Return drawing context
    )
   
  ; Export simple drawing functions to Arc
  (xdef 'make-canvas (lambda (w h) (make-canvas w h)))
  (xdef 'draw-point (lambda (dc x y) (send dc draw-point x y)))
Then I clicked "Run" in DrScheme and entered the following into Arc:

  Arc>(def gasket (x y w)
        (if (< w 1)
            (draw-point dc x y)
            (do (gasket x y (/ w 2))
  	        (gasket (+ x (/ w 2)) y (/ w 2))
                (gasket x (+ y (/ w 2)) (/ w 2)))))
  Arc>(= dc (make-canvas 300 300))
  Arc>(gasket 0 0 256)
Supporting additional graphics functions is left as an exercise to the reader. For more information on MrEd, see: http://download.plt-scheme.org/doc/372/html/mred/mred-Z-H-39...

I would be interested in knowing if there is a way to access this library from Arc directly, without needing to hack as.scm.

-----

2 points by soegaard 6112 days ago | link

If you want to learn how to use graphics in MzScheme, try asking at the PLT Scheme mailing list.

-----

3 points by olifante 6112 days ago | link

The simplest approach is probably to create SVG images.

-----