#lang racket
(require gigls/unsafe)

;;; File:
;;;   project/ellipses.rkt
;;; Authors:
;;;   Samuel A. Rebelsky
;;; Summary:
;;;   A simulated CSC 151 project that illustates some uses of gimp-tools.
;;;   We make columns of ovals.
;;; Citations:
;;;   Based on a project created by Colin Brooks '14 or so.  The primary
;;;   ideas are Colin's.  The implementation is mine.

;;; Procedure:
;;;   select-column-of-ovals!
;;; Parameters:
;;;   image, an image
;;;   operation, one of ADD or SUBTRACT
;;;   left, a real number
;;;   width, a real number
;;;   count, a positive integer
;;; Purpose:
;;;   Selects a column of count equal-sized ovals.  Each
;;;   oval has a left edge of left, a width of width, and
;;;   a height of (image-height image)/count.
;;; Produces:
;;;   [Nothing; called for the side effects]
(define select-column-of-ovals!
  (lambda (image operation left width count)
    (let ([height (/ (image-height image) count)])
      (for-each (lambda (i)
                  (image-select-ellipse! image operation
                                         left (* i height)
                                         width height))
                (iota count)))))

;;; Procedure:
;;;   select-many-ovals!
;;; Parameters:
;;;   image, an image
;;;   operation, one of ADD or SUBTRACT
;;;   count, a positive integer
;;; Purpose:
;;;   Select count columns of ovals, with one oval in the first column,
;;;   two in the second, three in the third, and so on and so forth.
;;; Produces:
;;;   [Nothing, called for the side effects]
(define select-many-ovals!
  (lambda (image operation count)
    (let ([width (/ (image-width image) count)])
      (for-each (lambda (i) 
                  (display "Selecting column ") (display i) (newline)
                  (select-column-of-ovals! image operation
                                           (* width i) ; left
                                           width       ; width
                                           (+ i 1)))   ; count
                (iota count)))))

; (image-series n width height)
;   Build one image in the series.  Documentation left incomplete
;   because this is an example for students.
(define image-series 
  (lambda (n width height)
    (let ([image (image-new width height)])
      (select-many-ovals! image ADD (+ n 1))
      (if (< n 400)
          (image-recompute! image 
                            (lambda (col row)
                              (irgb 0 0 (* 150 (/ col width)))))
          (let ()
            (context-set-fgcolor! (irgb 0 0 75))
            (image-fill! image)))
      (image-select-nothing! image))))

