#lang racket ;Kirsten Gillis and Nelson Schicke ;CSC 151-02 ;November 25, 2014 ;Project: Part 2 (require gigls/unsafe) ;Modeled after position->color from reading: http://www.cs.grinnell.edu/~weinman/courses/CSC151/2014F/readings/geometric-art-reading.html ;;; Procedure: ;;; position->color ;;; Parameters: ;;; n, an integer ;;; Purpose: ;;; Compute a color based on n. ;;; Produces: ;;; color, an integer-encoded RGB color ;;; Preconditions: ;;; 0 <= n <= 1000 ;;; Postconditions: ;;; Different n values are likely to give different colors. ;;; Nearby n values may give similar, but different colors. (define n->color (lambda (n) (irgb (+ 128 (* 128 (sin (* pi n 0.0625)))) (+ 128 (* 128 (cos (* pi n 0.0625)))) (+ 128 (* 128 (sin (* pi (+ n (* n 2) 0.0625)))))))) ;;; Procedure: ;;; brush-select! ;;; Parameters: ;;; turtle-list, a list of turtles ;;; n, an integer between 0 and 1000 (inclusive) ;;; Purpose: ;;; Select a brush based on n ;;; Produces: ;;;; turtle-select-brush!, a side-effect procedure ;;; Preconditions: ;;; 0 <= n <= 1000 ;;; n must be an integer ;;; turtle-list may not be empty ;;; Postconditions: ;;; brush-select! will attribute a brush to turtle-list ;;; turtle-list must be defined before running brush-select! (define brush-select! (lambda (n) (cond [(< n 100) (context-set-brush! "Animated Confetti")] [(< n 200) (context-set-brush! "Star Brush #3")] [(< n 300) (context-set-brush! "waves")] [(< n 400) (context-set-brush! "2. Block 01")] [(< n 500) (context-set-brush! "Confetti")] [(< n 600) (context-set-brush! "Tulip Print")] [(< n 700) (context-set-brush! "sphere (29)")] [(< n 800) (context-set-brush! "Manju's Flower")] [(< n 900) (context-set-brush! "2. Star")] [(< n 1000) (context-set-brush! "1. Pixel")]))) ;Draw-sin-with-parallel-lines! used with permission by Professor Weinman: ;http://www.cs.grinnell.edu/~weinman/courses/CSC151/2014F/readings/geometric-art-reading.html ;;; Procedure: ;;; draw-sin-with-parallel-lines! ;;; Parameters: ;;; image, an image ;;; n, an integer ;;; offset, an integer ;;; start-col, an integer ;;; mid-row, an integer ;;; Purpose: ;;; Draw a sequence of parallel lines, with the height of the ;;; parallel line dependent on the column. ;;; Produces: ;;; [Nothing, called for the side effect.] (define draw-sin-with-parallel-lines! (lambda (image n offset start-col mid-row) (let kernel! ([i 0] [col start-col] [row mid-row]) (context-set-fgcolor! (n->color n)) (when (< i n) (image-draw-line! image col row col (- row (* row (sin (* i pi 0.05))))) (kernel! (+ i 1) (+ col offset) row))))) ;;; Procedure: ;;; image-series ;;; Parameters: ;;; n, an integer ;;; width, a non-negative integer ;;; height, a non-negative integer ;;; Purpose: ;;; Create an image based on n that has the width and height given. ;;; Produces: ;;; image, an image ;;; Preconditions: ;;; [None Additional] ;;; Postconditions: ;;; 0 <= n <= 1000 ;;; width >= 0 ;;; height >= 0 (define image-series (lambda (n width height) (let ([image (image-compute (lambda (col row) (if (<= (+ (square (- col (mod n 50))) (square (- row (mod n 50)))) (square (/ n 20))) (irgb (mod (round (* (/ n 75) col)) 255) 0 (mod (round (* (/ n 80) row)) 255)) (irgb (mod n 255) (mod (* n 5) 255) (mod (round (/ n 20)) 255)))) width height)]) (image-show image) (context-set-fgcolor! (irgb (mod (* n 20) 255) (mod n 255) (mod (* n 70) 255))) (brush-select! n) (draw-sin-with-parallel-lines! image n (mod n 30) 0 (/ width 2)))))