I’m trying to create a xml file for Flam3 that contains multiple forms. I’m new to Common Lisp and I’m sure there’s a much better way to do what I’m trying to do.
Instead of calling the sexy function multiple times how can I just do a quick and dirty loop?
Here is the code in question:
;What the xml file should look like
;A nice little template
(defun sexy ()
(format nil
"<flame time=\"~d\" palette=\"~d\" zoom=\"~d\" size=\"640 480\" center=\"~d ~d\" background=\"0 0 0\" brightness=\"~d\" gamma=\"~d\" vibrancy=\"3\" hue=\"~d\">
<xform weight=\"~f\" color=\"~f\" spherical=\"~d\" coefs=\"~f ~f ~f ~f ~f ~f\"/>
<xform weight=\"~f\" color=\"~f\" julia=\"~d\" coefs=\"~f ~f ~f ~f ~f ~f\"/>
<xform weight=\"~f\" color=\"~f\" rings=\"~d\" coefs=\"~f ~f ~f ~f ~f ~f\"/>
<xform weight=\"~f\" color=\"~f\" butterfly=\"~d\" coefs=\"~f ~f ~f ~f ~f ~f\"/>
</flame>"
(random 100) (random 100) (random 3) (random 4) (random 4) (random 255) (random 10) (random 10)
(random 1.0) (random 1.0) 1 (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random 1.0)
(random 1.0) (random 1.0) 1 (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random 1.0)
(random 1.0) (random 1.0) 1 (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random 1.0)
(random 1.0) (random 1.0) 1 (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random 1.0) (random 1.0)
))
;Actually write the file using the sexy function
;But call it 10 times to create 10 different structures with random values
(defun xml-maker ()
(with-open-file (my-stream "test.flam3" :direction :output
:if-exists :supersede)
(format my-stream
"<test> ~a ~a ~a ~a ~a ~a ~a ~a ~a ~a </test>" (sexy) (sexy) (sexy) (sexy) (sexy) (sexy) (sexy) (sexy) (sexy) (sexy) )))
;Just call the program with the newly written file
(defun fract-maker ()
(progn (xml-maker)
(ext:shell "flam3-render < test.flam3")))
Do you mean something like this: