;;; File: ;;; random-art.scm ;;; Authors: ;;; Samuel A. Rebelsky ;;; Your Name Here ;;; Version: ;;; 0.2 of 30 October 2006 ;;; History: ;;; At end ;;; Summary: ;;; A collection of procedures that permit us to generate somewhat ;;; "random" art as a way of explorting patterns, colors, and such. ;;; Contents: ;;; General Procedures: ;;; (randomly-select lst) ;;; Choose one of the elements of lst. ;;; Color Procedures: ;;; (random-color) ;;; Pick and return an unpredictable color. ;;; (random-blue) ;;; Pick and return an unpredictable shade of blue. ;;; (random-grey) ;;; Pick and return an unpredictable shade of grey. ;;; Brush Procedures: ;;; (random-brush) ;;; Randomly select one of the brushes. ;;; (randomly-select-brush list-of-brushes) ;;; Randomly select one of the brushes in list-of-brushes. ;;; (random-circle-brush) ;;; Randomly select one of the circle brushes. ;;; Drawing Procedures: ;;; (random-line image width height) ;;; Draws an unprectable line in image, assuming that the image has ;;; the specified width and height. ; +--------------------+---------------------------------------------- ; | General Procedures | ; +--------------------+ ;;; Procedure: ;;; randomly-select ;;; Parameters: ;;; values, a list ;;; Purpose: ;;; Randomly select an element of values. ;;; Produces: ;;; value, a value ;;; Preconditions: ;;; values is nonempty. ;;; Postconditions: ;;; value is an element of values. ;;; value is equally likely to be any element of values. (define randomly-select (lambda (values) (list-ref values (random (length values))))) ; +------------------+------------------------------------------------ ; | Color Procedures | ; +------------------+ ;;; Procedure: ;;; random-color ;;; Parameters: ;;; (none) ;;; Purpose: ;;; Selects and returns a random color. ;;; Produces: ;;; color, a color. ;;; Postconditions: ;;; It is difficult to predict color. (define random-color (lambda () (list (random 256) (random 256) (random 256)))) ;;; Procedure: ;;; random-blue ;;; Parameters: ;;; (none) ;;; Purpose: ;;; Choose an unpredictable shade of blue. ;;; Produces: ;;; blue, a color ;;; Postconditions: ;;; blue is a shade of blue. ;;; It is difficult to predict which shade of blue it is. (define random-blue (let ((blues (list BLUE BLUE_VIOLET CADET_BLUE COBALT_BLUE CORN_FLOWER_BLUE DARK_SLATE_BLUE DEEP_MIDNIGHT_BLUE LIGHT_BLUE LIGHT_STEEL_BLUE MEDIUM_BLUE MEDIUM_SLATE_BLUE MIDNIGHT_BLUE NAVY_BLUE NEON_BLUE NEW_MIDNIGHT_BLUE OCEAN_BLUE PALE_BLUE RICH_BLUE ROYAL_BLUE SKY_BLUE SLATE_BLUE STEEL_BLUE))) (lambda () (randomly-select blues)))) ;;; Procedure: ;;; random-grey ;;; Parameters: ;;; (none) ;;; Purpose: ;;; Choose an unpredictable shade of grey. ;;; Produces: ;;; grey, a color ;;; Postconditions: ;;; grey is a shade of grey. ;;; It is difficult to predict what shade it is. ;;; Philosophy: ;;; We consider white and black shades of grey, too. (define random-grey (lambda () (let ((component (random 255))) (list component component component)))) ; +------------------+------------------------------------------------ ; | Brush Procedures | ; +------------------+ ;;; Procedure ;;; random-brush ;;; Parameters: ;;; (none) ;;; Purpose: ;;; Select one of the brushes. ;;; Produces: ;;; (nothing) ;;; Postconditions: ;;; It is difficult to predict the brush. (define random-brush (lambda () (randomly-select-brush (list-brushes)))) ;;; Procedure: ;;; randomly-select-brush ;;; Parameters: ;;; brushes, a list of strings ;;; Purpose: ;;; Select one of brushes. ;;; Produces: ;;; (nothing) ;;; Preconditions: ;;; All the strings in brushes name valid brushes. ;;; Postconditions: ;;; The current brush is an element of brushes. ;;; It is equally likely that each element of brushes is now the ;;; active brush (define randomly-select-brush (lambda (brushes) (set-brush (randomly-select brushes)))) ;;; Procedure: ;;; random-circle-brush ;;; Parameters: ;;; (none) ;;; Purpose: ;;; Randomly select one of the circle brushes. ;;; Produces: ;;; (nothing) ;;; Preconditions: ;;; (none) ;;; Postconditions: ;;; The current brush is one of the circle brushes. (define random-circle-brush (lambda () (randomly-select-brush (list "Circle (01)" "Circle (03)" "Circle (05)" "Circle (07)" "Circle (09)" "Circle (11)" "Circle (13)" "Circle (15)" "Circle (17)" "Circle (19)")))) ; +--------------------+---------------------------------------------- ; | Drawing Procedures | ; +--------------------+ ;;; Procedure: ;;; random-line ;;; Parameters: ;;; image, an image ;;; width, an integer ;;; height, an integer ;;; Purpose: ;;; Draw a random line in the image, assuming that its width ;;; and height are as specified. ;;; Produces: ;;; (nothing) ;;; Postconditions: ;;; A new line has been added to image, using the current color ;;; and brush. (define random-line (lambda (image width height) (line image (random width) (random height) (random width) (random height)))) ; +-------------------+----------------------------------------------- ; | Hybrid Procedures | ; +-------------------+ ;;; Procedure: ;;; splat ;;; Parameters: ;;; image, an image ;;; width, an integer ;;; height, an integer ;;; Purpose: ;;; Draw a line between random points, using a random color and ;;; a random brush. ;;; Produces: ;;; (nothing) ;;; Postconditions: ;;; The foreground color may have changed. ;;; The brush may have changed. ;;; The image now contains another line. (define splat (lambda (image width height) (set-fgcolor (random-color)) (random-brush) (random-line image width height))) ; +---------+--------------------------------------------------------- ; | History | ; +---------+ ; Tuesday, 24 October 2006 (no version) [Samuel A. Rebelsky] ; * Wrote the procedures as part of lab on algorithmic art. ; Thursday, 26 October 2006 (v 0.1) [Samuel A. Rebelsky] ; * Created this library. ; Monday, 30 October 2006 (v 0.2) [Samuel A. Rebelsky] ; * Updated random-blue to match documentation.