;;; -*- lexical-binding: t -*- ;; ;; -------------------------------------------------------------------------- (require 'cl-lib) (cl-pushnew "." load-path :test #'string=) (require 'luki-lisp) ;; -------------------------------------------------------------------------- (-> 'bad-borderless) (-> 'bad-box) (-> 'bad-color) (-> 'bad-write) ;; -------------------------------------------------------------------------- (defclass solid (borderless) ((name :initform (@f "solid-%d" (random 100))) (fg :initform (seq-random-elt (bad-fg-colors))) (spc :initform '(?#)) (w :initform #1=3) (h :initform #1#) (w-min :initform #1#) (h-min :initform #1#))) ;; -------------------------------------------------------------------------- (defclass triangle (solid) ((name :initform (@f "triangle-%d" (random 100))))) ;; -------------------------------------------------------------------------- (cl-defmethod bad-add ((b box) (tri triangle) &rest _) (~ (w h sub) b (~ (bg dist-fg fg (ew w) (eh h) w-max h-max min-x min-y x y) tri (setf bg (or bg (bad-bg-random))) (setf dist-fg (or dist-fg our-black-b)) (setf fg (or fg our-white-b)) (setf ew (or ew (- w 1))) (setf eh (or eh (- h 1))) (setf w-max (or w-max ew)) (setf h-max (or h-max eh)) (setf min-x (or min-x 0)) (setf min-y (or min-y 0)) (setf x (or x (1+ min-x))) (setf y (or y (1+ min-y)))) (bad-update tri) (pushlast tri sub))) (cl-defmethod bad-update ((tri triangle) &optional force) (when (or (! (@ tri data)) force) (~ (w h spc) tri (cl-loop with end = (1- h) for l from 0 to end for c from w downto 1 for p from 0 to end collect (concat (make-list c (1st spc)) (make-list p bad-nonsolid)) into res finally do (bad-set-data tri res))))) ;; -------------------------------------------------------------------------- (cl-defmethod bad-size :after ((tri triangle) &rest _) (~ (w h) tri (setf h w)) (bad-update tri 'force)) ;; -------------------------------------------------------------------------- (cl-defmethod bad-add ((b box) (tri triangle)) (~ (w h sub) b (~ ((tw w) (th h) w-max h-max x y min-x min-y) tri (setf tw #1=3) (setf th #1#) (setf w-max (- w 2)) (setf h-max (- h 2)) (setf x #3=1) (setf y #4=1) (setf min-x #3#) (setf min-y #4#)) (bad-update tri 'force) (push tri sub))) ;; -------------------------------------------------------------------------- (<- 'bad-triangle)