[plt-scheme] Nifty assignment help

From: Noel Welsh (noelwelsh at gmail.com)
Date: Wed Mar 11 05:50:20 EDT 2009

On Tue, Mar 10, 2009 at 2:33 PM, Todd O'Bryan <toddobryan at gmail.com> wrote:
> Where should I look for a better way to do it?

Here, perhaps:

#lang scheme/gui

(define (make-plotter drawing-fn size)
  (lambda (canvas dc)
    (for* ((x (in-range size))
           (y (in-range size)))
          (let* ([intensity (inexact->exact (round (* (/ (add1
(drawing-fn x y)) 2) 255)))]
                 [colour (make-object color% intensity intensity intensity)])
            ;;(printf "~a ~a ~a\n" intensity x y)
            (send dc set-pen colour 1 'solid)
            (send dc draw-point x y)))))

(define (draw-grayscale size drawing-fn)
  (define frame (new frame%
                     [label "Random Art"]
                     [width size]
                     [height size]))
  (define canvas (new canvas%
                      [parent frame]
                      [paint-callback (make-plotter drawing-fn size)]))
  (send frame show #t))

(define (example1 x y)
  ;; some random stuff
  (sin (* (sin (* (cos x) y))
          (cos (*
                  (sin (* (sin y) (cos x)))
                  (cos (*  (cos (* y x)))))))))

(define (example2 x y)
  (if (> x 200)

;;(draw-grayscale 400 example1)

Posted on the users mailing list.