Created
December 4, 2012 18:19
-
-
Save mohiji/4207138 to your computer and use it in GitHub Desktop.
Using a cond in a let form makes me feel a little greasy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar *grass-base-color* (list 64 137 44)) | |
(defvar *grass-medium-color* (mapcar (lambda (x) (round (* x 0.9))) *grass-base-color*)) | |
(defvar *grass-dark-color* (mapcar (lambda (x) (round (* x 0.8))) *grass-base-color*)) | |
(defun generate-grass-texture2 (file width height) | |
(let* ((png (make-instance 'zpng:png | |
:color-type :truecolor-alpha | |
:width width | |
:height height)) | |
(image (zpng:data-array png))) | |
(loop for x from 0 below width do | |
(loop for y from 0 below height do | |
(let* ((chance (random 4)) | |
; 25% chance for the dark color, 50% for medium, 25% for bright | |
(color (cond ((= 0 chance) | |
*grass-dark-color*) | |
((or (= 1 chance) | |
(= 2 chance)) | |
*grass-medium-color*) | |
(t *grass-base-color*)))) | |
(setf (aref image y x 0) (elt color 2)) | |
(setf (aref image y x 1) (elt color 1)) | |
(setf (aref image y x 2) (elt color 0)) | |
(setf (aref image y x 3) 255)))) | |
(zpng:write-png png file))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment