Pretty Pictures from Genetic Algorithms
About this project
Details:
About this project: This project
is a reimplementation of my final
COMP 314 project, pretty pictures (via genetic algorithms). (originally by Dan Wallach)
Each picture is produced from a tree of functions (listed below), acting on x
and y coordinates in [-1,1], and mapping the results to RGB values 0-255. Breeding two pictures together involves taking a random subtree from one and splicing
it in a random place in the other. The backend script that draws the pictures
is written in Python, and the function tree is passed in a modified version of
JSON (using single quotes instead of double quotes, so they don't have to be URL encoded).
Try these pretty pictures!
- (abs (sub-wrap (neg (ccrgb (ru (ru (num 0.6614554081190059))) (log-clip (abs (div-clip (abs (cchsl (ccrgb (num 0.5266760532380341) (num 0.2037882282789114) y) x x)) (mul-wrap (sub-wrap (atan-wrap (num 0.2710625018544712)) (num 0.46994645301411775)) (abs x))))) (rd (cchsl (num 0.811607978527779) y x)))) (abs y)))
- (div-wrap (abs (div-clip (sub-clip (cchsl x (num 0.5522413404801835) (neg (sin (atan-wrap (num 0.8416469025349831))))) (cchsl (num 0.6429928276228649) (neg (abs y)) (div-clip (cchsl (mul-wrap x y) (cchsl (ccrgb x (div-wrap x y) x) x (exp-clip x)) (ccrgb (num 0.8167221711670928) (sub-clip y x) x)) y))) y)) (cchsl (ru (ccrgb (neg (ru y)) (abs (sub-clip (div-wrap x y) (add-clip x (cchsl (log-wrap (ccrgb (num 0.09141941365047113) y y)) y (num 0.30011079353156145))))) y)) (ccrgb (ru (add-clip x y)) (add-wrap (rd x) (num 0.7744101640567105)) y) (num 0.34666343576153713)))
- (sub-clip (cchsl (abs (div-clip (sub-clip (cchsl x (num 0.5522413404801835) (neg (sin (atan-wrap (num 0.8416469025349831))))) (cchsl (num 0.6429928276228649) (neg (abs y)) (div-clip (cchsl (mul-wrap x y) (cchsl (ccrgb x (div-wrap x y) x) x (exp-clip x)) (ccrgb (num 0.8167221711670928) (sub-clip y x) x)) y))) y)) (abs (div-clip (sub-clip (cchsl x (num 0.5522413404801835) (neg (sin (atan-wrap (num 0.8416469025349831))))) (cchsl (num 0.6429928276228649) (neg (abs y)) (div-clip (cchsl (mul-wrap x y) (cchsl (ccrgb x (div-wrap x y) x) x (exp-clip x)) (ccrgb (num 0.8167221711670928) (sub-clip y x) x)) y))) y)) (abs (div-clip (sub-clip (cchsl x (num 0.5522413404801835) (neg (sin (atan-wrap (num 0.8416469025349831))))) (cchsl (num 0.6429928276228649) (neg (abs y)) (div-clip (cchsl (mul-wrap x y) (cchsl (ccrgb x (div-wrap x y) x) x (exp-clip x)) (ccrgb (num 0.8167221711670928) (sub-clip y x) x)) y))) y))) (cchsl (num 0.6429928276228649) (neg (abs y)) (div-clip (cchsl (mul-wrap x y) (cchsl (ccrgb x (div-wrap x y) x) x (exp-clip x)) (ccrgb (num 0.8167221711670928) (sub-clip y x) x)) y)))
- (ccrgb (exp-wrap (neg (sub-wrap x (sub-wrap (sub-clip (sub-wrap x y) (neg (atan-wrap (add-wrap x y)))) y)))) (neg (sub-wrap x (sub-wrap (sub-clip (sub-wrap x y) (neg (atan-wrap (add-wrap x y)))) y))) (num 0.37767491866913594 ))
- (neg (sub-wrap (sub-wrap (num 0.12345183270643267) y) (neg (atan-wrap (cchsl (add-wrap y (exp-wrap y)) (cos (log-wrap y)) (add-clip (cchsl (neg x) (num 0.3833093051145148) x) (num 0.5117598243776572)))))))
- (cchsl x (exp-wrap x) (cchsl (num 0.11385156752423187) (sub-clip (rd (abs (cos (abs (add-clip y x))))) (atan-wrap (num 0.6693146834356939))) (cchsl (ccrgb y (log-wrap (neg (sub-clip x y))) (cchsl (log-clip (div-wrap x y)) (log-wrap y) (atan-wrap (num 0.6652075928655149 )))) (rd (ru y)) (mul-clip (sin (atan-clip x)) y))))
Source files:
I also am working on a version in Haskell; here are the source files:
- Png.hs - code to write (and hopefully read someday) PNG files - taken from here and modified.
- MakePng.hs - draws the PNG file given a function.
- cgiHandler.hs - the CGI handler.
Here's the list of functions. Ones with a * can take their values outside
[-1,1], and so must be followed by "-clip" or "-wrap" (describing how they
return their values to [-1,1]).
- num (takes a value argument)
- x
- y
- atan*
- abs
- cos
- exp*
- log*
- neg
- rd (round down to an integer)
- ru (round up to an integer)
- sin
- add*
- div*
- mul*
- sub*
- ccrgb (color conditional - arguments are red, green, blue channels)
- cchsl (color conditional - arguments are HSL channels)