(require "asdf")
(require "spinneret")
(require "generative")
(defun image-path (image)
  (format nil "/home/leon/Programming/Blog/images/gallery/iso_stacks_current/~a.png" image))
(defun rel-image-path (image)
  (format nil "/images/gallery/iso_stacks_current/~a.png" image))

(defparameter max-size 128)
(defparameter image-size (cons 1000 1000))
(defparameter padding 20)
(defmacro loopv ((sym a b) &rest body)
  `(let ((a ,a) (b ,b))
     (loop for x from (x a) to (x b) do
       (loop for y from (y a) to (y b) do
         (loop for z from (z a) to (z b) do
           (let ((,sym (ivec3 x y z))) ,@body))))))

(defun add-stack (origin size by thick add-rects)
  (let* ((to (div size (add by thick)))
         (offset (randrv (ivec3 0) (add by thick))))
    (loopv (n (ivec3 0) to)
           (add-cuboid (add offset (add origin (mult n (add by thick))))
                       thick
                       add-rects))))

(defun add-thick-stack (size-range step-range thick-range add-rects)
    (add-stack (randivr (cons (- (cdr size-range)) (cdr size-range)))
               (randivr size-range)
               (randivr step-range)
               (randivr thick-range)
               add-rects))

(defparameter *images* '())
(defun make-image (i)
  (let* ((seed (random-seed))
         (*random-state* (seed-state seed))
         (file-name (image-path i)))
    (with-image (add-rects *headers* *params*) file-name image-size padding
                (defheader size max-size)
                (defheader source "iso_stacks")
                (defheader seed (format nil "#x~8,'0X" seed))

                (defparam n-stacks (random-list-element (list 16 32 64 128)))
                (defparam size-range (cons 1 (random-list-element (list 16 32 64 128))))
                (defparam step-range (cons 1 (random-list-element (list 16 32 64 128))))
                (defparam thick-range (cons 1 (random-list-element (list 16 32 64 128))))

                (push (list i *headers* *params*) *images*)

                (dotimes (i n-stacks)
                  (add-thick-stack size-range step-range thick-range add-rects)))))

(loop for i from 0 to 30 do (make-image i))
(make-gallery *images*)
  • #x3AF7576D

    • thick-range: (1 . 128)
    • step-range: (1 . 128)
    • size-range: (1 . 128)
    • n-stacks: 32
  • #x6326FC7D

    • thick-range: (1 . 64)
    • step-range: (1 . 32)
    • size-range: (1 . 128)
    • n-stacks: 32
  • #xE54FD063

    • thick-range: (1 . 64)
    • step-range: (1 . 32)
    • size-range: (1 . 64)
    • n-stacks: 16
  • #x8BB6D1F4

    • thick-range: (1 . 64)
    • step-range: (1 . 32)
    • size-range: (1 . 128)
    • n-stacks: 16
  • #xB440DE44

    • thick-range: (1 . 32)
    • step-range: (1 . 32)
    • size-range: (1 . 64)
    • n-stacks: 16
  • #x93CEC30D

    • thick-range: (1 . 16)
    • step-range: (1 . 32)
    • size-range: (1 . 128)
    • n-stacks: 16
  • #x873FC414

    • thick-range: (1 . 16)
    • step-range: (1 . 16)
    • size-range: (1 . 32)
    • n-stacks: 128
  • #x3B5EDAF4

    • thick-range: (1 . 32)
    • step-range: (1 . 128)
    • size-range: (1 . 128)
    • n-stacks: 128
  • #x196D9354

    • thick-range: (1 . 128)
    • step-range: (1 . 128)
    • size-range: (1 . 64)
    • n-stacks: 32
  • #x84D03B55

    • thick-range: (1 . 32)
    • step-range: (1 . 64)
    • size-range: (1 . 16)
    • n-stacks: 64
  • #xABD7A789

    • thick-range: (1 . 64)
    • step-range: (1 . 32)
    • size-range: (1 . 64)
    • n-stacks: 16
  • #x27FBF500

    • thick-range: (1 . 32)
    • step-range: (1 . 16)
    • size-range: (1 . 64)
    • n-stacks: 64
  • #x5B59ACE7

    • thick-range: (1 . 16)
    • step-range: (1 . 32)
    • size-range: (1 . 16)
    • n-stacks: 64
  • #xFAA112AD

    • thick-range: (1 . 32)
    • step-range: (1 . 16)
    • size-range: (1 . 128)
    • n-stacks: 64
  • #x86DE1195

    • thick-range: (1 . 32)
    • step-range: (1 . 64)
    • size-range: (1 . 32)
    • n-stacks: 128
  • #x69C07713

    • thick-range: (1 . 64)
    • step-range: (1 . 64)
    • size-range: (1 . 64)
    • n-stacks: 128
  • #x7FB1ED4B

    • thick-range: (1 . 32)
    • step-range: (1 . 16)
    • size-range: (1 . 64)
    • n-stacks: 16
  • #x59C471EF

    • thick-range: (1 . 32)
    • step-range: (1 . 32)
    • size-range: (1 . 32)
    • n-stacks: 128
  • #xB430FD2E

    • thick-range: (1 . 32)
    • step-range: (1 . 128)
    • size-range: (1 . 128)
    • n-stacks: 128
  • #x2A4F3BA6

    • thick-range: (1 . 16)
    • step-range: (1 . 128)
    • size-range: (1 . 16)
    • n-stacks: 128
  • #x948BE515

    • thick-range: (1 . 128)
    • step-range: (1 . 64)
    • size-range: (1 . 16)
    • n-stacks: 32
  • #x2F57A37D

    • thick-range: (1 . 128)
    • step-range: (1 . 32)
    • size-range: (1 . 16)
    • n-stacks: 32
  • #xFD99A0A0

    • thick-range: (1 . 32)
    • step-range: (1 . 32)
    • size-range: (1 . 16)
    • n-stacks: 16
  • #xFBEB6458

    • thick-range: (1 . 64)
    • step-range: (1 . 128)
    • size-range: (1 . 16)
    • n-stacks: 128
  • #x1CDC40CD

    • thick-range: (1 . 32)
    • step-range: (1 . 128)
    • size-range: (1 . 32)
    • n-stacks: 32
  • #x8322A913

    • thick-range: (1 . 128)
    • step-range: (1 . 16)
    • size-range: (1 . 16)
    • n-stacks: 16
  • #xBDB03DBA

    • thick-range: (1 . 16)
    • step-range: (1 . 128)
    • size-range: (1 . 128)
    • n-stacks: 16
  • #xBDA3E31D

    • thick-range: (1 . 16)
    • step-range: (1 . 128)
    • size-range: (1 . 64)
    • n-stacks: 32
  • #x125EF477

    • thick-range: (1 . 32)
    • step-range: (1 . 128)
    • size-range: (1 . 16)
    • n-stacks: 128
  • #x23A3F142

    • thick-range: (1 . 64)
    • step-range: (1 . 128)
    • size-range: (1 . 64)
    • n-stacks: 128
  • #xB2CEDD66

    • thick-range: (1 . 32)
    • step-range: (1 . 32)
    • size-range: (1 . 32)
    • n-stacks: 64