;; ASCII Zones effect - different character sets for different brightness zones
;; Dark areas use simple chars, mid uses standard, bright uses blocks
(require-primitives "ascii")

(define-effect ascii_zones
  :params (
    (char_size :type int :default 8 :range [4 32])
    (dark_threshold :type int :default 80 :range [0 128])
    (bright_threshold :type int :default 180 :range [128 255])
    (color_mode :type string :default "color")
  )
  (let* ((sample (cell-sample frame char_size))
         (colors (nth sample 0))
         (luminances (nth sample 1))
         ;; Start with simple chars as base
         (base-chars (luminance-to-chars luminances "simple" 1.2))
         ;; Map each cell to appropriate alphabet based on brightness zone
         (zoned-chars (map-char-grid base-chars luminances
                        (lambda (r c ch lum)
                          (cond
                            ;; Bright zones: use block characters
                            ((> lum bright_threshold)
                             (alphabet-char "blocks" (floor (/ (- lum bright_threshold) 15))))
                            ;; Dark zones: use simple sparse chars
                            ((< lum dark_threshold)
                             (alphabet-char " .-" (floor (/ lum 30))))
                            ;; Mid zones: use standard ASCII
                            (else
                             (alphabet-char "standard" (floor (/ lum 4)))))))))
    (render-char-grid frame zoned-chars colors char_size color_mode (list 0 0 0))))
