emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/focus 8028fc088f 04/82: Improved average color function


From: ELPA Syncer
Subject: [nongnu] elpa/focus 8028fc088f 04/82: Improved average color function
Date: Tue, 6 Sep 2022 04:58:54 -0400 (EDT)

branch: elpa/focus
commit 8028fc088f6fb13411db835e5399e973e9a194cc
Author: Lars Tveito <larstvei@ifi.uio.no>
Commit: Lars Tveito <larstvei@ifi.uio.no>

    Improved average color function
    
    It assumed to receive hex-strings, fixed with using color-name-to-rgb
    instead.
---
 focus-mode.el | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/focus-mode.el b/focus-mode.el
index 47d6825e4c..7e876d72e6 100644
--- a/focus-mode.el
+++ b/focus-mode.el
@@ -1,3 +1,5 @@
+(require 'cl-lib)
+
 (defvar-local focus-pre-overlay nil)
 (defvar-local focus-post-overlay nil)
 
@@ -7,13 +9,13 @@
 (defun focus-search-forward (regex)
   (save-excursion (re-search-forward regex nil t)))
 
-(defun focus-hexstr-to-int (str)
-  (read (concat "#x" (substring str 1))))
-
-(defun focus-average-colors (hstr1 hstr2 &rest hstrs)
-  (let* ((strs (cons hstr1 (cons hstr2 hstrs)))
-         (avg (/ (apply '+ (mapcar 'focus-hexstr-to-int strs)) 2)))
-    (format "#%X" avg)))
+(defun focus-average-colors (color &rest colors)
+  (let* ((colors (cons color colors))
+         (colors (mapcar 'color-name-to-rgb colors))
+         (len    (length colors))
+         (sums   (apply 'cl-mapcar '+ colors))
+         (avg    (mapcar (lambda (v) (/ v len)) sums)))
+    (apply 'color-rgb-to-hex avg)))
 
 (defun focus-move-focus ()
   (let* ((pre  (or (focus-search-backward "^\n") (point-min)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]