SICP/shared/lib-draw.scm

27 lines
811 B
Scheme
Raw Normal View History

(define (draw-to-py painter name)
2021-04-25 14:57:17 +02:00
(define py-name (string-append "shared/" name ".py"))
(define img-name (string-append name ".png"))
(define head (string-append
"from PIL import Image, ImageDraw\n"
"im = Image.new('RGB', (1921, 1081))\n"
"draw = ImageDraw.Draw(im)\n"))
(define tail (string-append
"im.save('" img-name "', 'PNG')\n"))
(let ((port (open-output-file py-name)))
(define (draw-line v1 v2)
(define n2s number->string)
(display
(string-append
"draw.line(("
(n2s (xcor-vect v1)) ", "
(n2s (ycor-vect v1)) ", "
(n2s (xcor-vect v2)) ", "
(n2s (ycor-vect v2)) "), "
"fill=128)\n") port))
(display head port)
(painter draw-line)
(display tail port)
(close-output-port port)))