;;; File: ;;; face.scm ;;; Author: ;;; Samuel A. Rebelsky ;;; Summary: ;;; A simple example of parameterized face drawing ;;; Version: ;;; 1.0 of April 2003 ;;; Procedures: ;;; (face alpha beta gamma) ;;; Draw a parameterized face. The higher alpha, beta, and ;;; gamma are (limit of 100), the more stressed the face seems. ;;; (numeric-face num) ;;; Draw a simpler parameterized face. Once again, higher numbers ;;; should look more stressed. 0 <= num <= 10000. ;;; (saveface num) ;;; Creates the given face and saves to a file. ;;; (showface num) ;;; Creates the given face and displays it. ;;; History: ;;; At end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Libraries ; ;;;;;;;;;;;;; (load "/home/rebelsky/Web/Glimmer/ScriptFu/Code/gsfu.scm") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Library Procedures ; ;;;;;;;;;;;;;;;;;;;;;; ;;; Procedure: ;;; face ;;; Parameters: ;;; alpha, a number between 0 and 100, inclusive ;;; beta, a number between 0 and 100, inclusive ;;; gamma, a number between 0 and 100, inclusive ;;; Purpose: ;;; Builds a new image containing a simple "smiley" face ;;; Produces: ;;; image-layer, a two element list containing the id of the ;;; image and layer ;;; Preconditions: ;;; Types are met ;;; Postconditions: ;;; image-layer contains ids of a new image and a layer on that ;;; image ;;; The given image contains a smiley face (or some approximation ;;; thereof). (define face (lambda (alpha beta gamma) (let* ((image-layer (gsfu-new-image 128 128)) (image (car image-layer)) (layer (cadr image-layer)) (color-offset (* alpha 0.64)) (halfwidth (- 64 (* beta 0.16))) ; More stressed - narrower (quarterwidth (/ halfwidth 2)) (smileheight (- 64 (* gamma 0.63))) ) ; Faces move from yellow (happy) to grey (stressed) (gimp-palette-set-foreground (list (- 255 color-offset) (- 255 color-offset) (* 3 color-offset))) ; Draw the oval for the face (gimp-ellipse-select image (- 64 halfwidth) 0 ; x y (+ halfwidth halfwidth) 128 ; width height REPLACE 0 0 0) (gimp-edit-fill layer 0) (gimp-selection-none image) ; Draw the eyes (gimp-palette-set-foreground (list 0 0 128)) (gimp-ellipse-select image 40 40 16 16 REPLACE 0 0 0) (gimp-edit-fill layer 0) (gimp-ellipse-select image 72 40 16 16 REPLACE 0 0 0) (gimp-edit-fill layer 0) (gimp-selection-none image) ; Draw a simple mouth (gimp-palette-set-foreground (list 255 0 0)) (gimp-ellipse-select image (- 64 quarterwidth) (- 100 smileheight) ; x y halfwidth smileheight ; width height REPLACE 0 0 0) (gimp-ellipse-select image (- 64 quarterwidth) (- 92 smileheight) ; x y halfwidth smileheight ; width height SUB 0 0 0) (gimp-edit-fill layer 0) (gimp-selection-none image) ; Return the list of image and layer ; (print image-layer) image-layer ))) ;;; Procedure: ;;; numeric-face ;;; Parameters: ;;; num, the number of the face ;;; Parameters: ;;; num, the number of the face ;;; Purpose: ;;; Generates a new face and shows the face ;;; Produces: ;;; image-layer, a list of the ids of image and layer ;;; Preconditions: ;;; 0 <= num <= 10000 ;;; Postconditions: ;;; image-layer contains ids of a new image and a layer on that ;;; image ;;; The given image contains a smiley face (or some approximation ;;; thereof). ;;; Note: ;;; We convert num to three numbers between 0 and 100 for calling ;;; face. The formulae for doing so are currently somewhat simplistic. ;;; A good designer could come up with better ones. (define numeric-face (lambda (num) (face (/ num 100) (mod num 100) (/ (mod num 501) 5)))) ;;; Procedure: ;;; saveface ;;; Parameters: ;;; num, the nmber of the face ;;; Purpose: ;;; Generates a new face and saves the face in a file ;;; Produces: ;;; image-layer, a list of the ids of image and layer ;;; Preconditions: ;;; 0 <= num <= 10000 ;;; Postconditions: ;;; image-layer contains ids of a new image and a layer on that ;;; image ;;; The current directory contains a file named face-####.png, ;;; where #### is the value of num. ;;; That file contains a smiley face of the appropriate form. (define saveface (lambda (num) (let ((image-layer (numeric-face num))) (gsfu-save-png (string-append "face-" (number->string num) ".png") (car image-layer) (cadr image-layer))))) ;;; Procedure: ;;; showface ;;; Parameters: ;;; num, the number of the face ;;; Purpose: ;;; Generates a new face and shows the face ;;; Produces: ;;; image-layer, a list of the ids of image and layer ;;; Preconditions: ;;; 0 <= num <= 10000 ;;; Postconditions: ;;; image-layer contains ids of a new image and a layer on that ;;; image ;;; The given image contains a smiley face (or some approximation (define showface (lambda (num) (let ((image-layer (numeric-face num))) (gimp-display-new (car image-layer)) image-layer))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; History ; ;;;;;;;;;;; ;;; Tuesday, 15 April 2003 [Version 1.0] ;;; Created.