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

(defparameter max-size 128)
(defparameter image-size (cons 1000 1000))
(defparameter padding 20)
(defun add-stack (origin size by axis add-rects)
  (let* ((limit (max-value (mult size axis)))
         (offset (randr 0 (1+ (rem limit by)))))
    (loop for n from 0 to (floor limit by) do
      (add-cuboid (add origin (mult axis (+ (* n by) offset)))
                  (add axis (mult size (sub (ivec3 1) axis)))
                  add-rects))))

(defun add-thick-stack (size-range step-range add-rects)
  (let* ((size (randrv (ivec3 (car size-range))
                       (ivec3 (cdr size-range))))
         (origin (randrv (ivec3 0)
                         (sub (ivec3 max-size) size)))
         (by (randrr step-range)))
    (add-stack origin size by (random-axis) 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 (randr 2 15))
      (defparam size-range (cons 20 100))
      (defparam step-range (cons 1 20))

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

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

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

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 9
  • #x4CEC4528

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 3
  • #x441228B9

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 9
  • #xC93F3EB1

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 7
  • #x74FCB65C

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 8
  • #x2E884B2D

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 6
  • #x0AF52104

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 10
  • #x0219232B

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 8
  • #x50308751

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 5
  • #xC2ED9424

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 9
  • #x2F380233

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 4
  • #x7995FDCD

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 12
  • #x4822FC4A

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 8
  • #x9DEF8285

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 4
  • #x7C3CCE73

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 4
  • #x79BB0B47

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 9
  • #x1D0FD458

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 13
  • #x0FBCE7A8

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 9
  • #xF2B541AF

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 12
  • #xB1B924DA

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 5
  • #x06BDF04B

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 6
  • #x3367135D

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 12
  • #x227180F8

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 13
  • #x718DB78D

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 8
  • #x2B541872

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 5
  • #x7564EC1C

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 8
  • #x09EB15B9

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 4
  • #xA7701BA0

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 11
  • #xD9150AC3

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 12
  • #xFDD63905

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 14
  • #x0EC95931

    • step-range: (1 . 20)
    • size-range: (20 . 100)
    • n-stacks: 5