;;; -*- lexical-binding: t -*- ;; ;; -------------------------------------------------------------------------- (require 'cl-lib) (cl-pushnew "." load-path :test #'string=) (require 'luki-lisp) ;; -------------------------------------------------------------------------- (-> 'bad-color) (-> 'bad-helpers) ;; -------------------------------------------------------------------------- (let* ((p1 (* 9 (** 2 -4))) (p2 (- 1 p1)) c1-last r1 g1 b1 c2-last r2 g2 b2 r g b res) (defun bad-blend (c1 c2) (let ((c1-alike (s= c1-last c1)) (c2-alike (s= c2-last c2))) (unless (& c1-alike c2-alike) (cl-flet ((clp (c) (min 255 (max 0 c)))) (unless c1-alike (setq c1-last c1) (pcase-let ((`(,re ,gr ,bl) (mapcar (L (c) (clp (* c p1))) (bad-color-values c1)))) (setq r1 re) (setq g1 gr) (setq b1 bl))) (unless c2-alike (setq c2-last c2) (pcase-let ((`(,re ,gr ,bl) (mapcar (L (c) (clp (* c p2))) (bad-color-values c2)))) (setq r2 re) (setq g2 gr) (setq b2 bl))) (setq r (clp (+ r1 r2))) (setq g (clp (+ g1 g2))) (setq b (clp (+ b1 b2))) (setq res (@f "#%.2x%.2x%.2x" r g b)))) res))) (declare-function bad-blend nil) ;; -------------------------------------------------------------------------- (defun test-bad-blend () (let ((n (** 2 12))) (// (bad-timing (cl-loop repeat n for c1 = (bad-bg-random) for c2 = (bad-fg-random) do (bad-blend c1 c2))) n))) (defun test-bad-80x30 () (bad-timing (let ((n (* 80 30))) (cl-loop repeat n for c1 = (bad-bg-random) for c2 = (bad-fg-random) do (bad-blend c1 c2))))) ; (test-bad-80x30) ;; Worst-case scenario drawing blending for every char in a 80x30 terminal. ;; Note: With byte-compilation on, native-compilation not available on OpenBSD. ;; ;; (@f "%.2f s" (* 80 30 (test-bad-blend))) ; 0.13 s ;; (@f "%.2f FPS" (/ 1 (* 80 30 (test-bad-blend)))) ; 7.69 FPS ;; ;; Oh, no! Too slow. ;; ;; -------------------------------------------- ;; FPS where ;; -------------------------------------------- ;; 24 cinema movies ;; 30 old games ;; 60 modern consoles (e.g., PS5) ;; 120 eSport competitive players ;; 240 eSport challengers ;; 360 eSport champions ;; -------------------------------------------- ;; https://www.gpumag.com/good-fps-for-gaming ;; -------------------------------------------- (<- 'bad-blend)