unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yilkal Argaw <yilkalargawworkneh@gmail.com>
To: Emacs Devel <emacs-devel@gnu.org>
Subject: Adding some convenience functions to color.el
Date: Fri, 9 Jun 2023 02:57:41 +0300	[thread overview]
Message-ID: <CAJddU=rZHpYo1w0m2hrdvO57T5c7mN8xm6oTqLmN9nFYqwwWyw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1217 bytes --]

Hi
Today I was messing around with some theme that  made use of color.el and I
noticed some functions that might be of use could be added to color.el to
help with the conditionally assigning setting some colors based on
lightness or darkness of some other color. I wondered if it might be useful
to other users and if it might be worth adding it to color.el. I

diff --git a/lisp/color.el b/lisp/color.el
index f68cf5e6b17..3740c3d5a7c 100644
--- a/lisp/color.el
+++ b/lisp/color.el
@@ -119,6 +119,18 @@ inclusive."
        (color-hue-to-rgb m1 m2 H)
        (color-hue-to-rgb m1 m2 (mod (- H (/ 3.0)) 1))))))

+(defun color-name-to-hsl (color)
+ "Convert COLOR to HSL."
+  (apply #'color-rgb-to-hsl (color-name-to-rgb color)))
+
+(defun color-name-light-p (color)
+   "Return non-nil if COLOR is on the lighter side."
+  (when color (>= (caddr (color-name-to-hsl color) 0.5))))
+
+(defun color-name-dark-p (color)
+  "Return non-nil if COLOR is on the darker side."
+  (when color (not (color-name-light-p color))))
+
 (defun color-complement-hex (color)
   "Return the color that is the complement of COLOR, in hexadecimal
format."
   (apply 'color-rgb-to-hex (color-complement color)))


With Regards
Yilkal Argaw

[-- Attachment #2: Type: text/html, Size: 1441 bytes --]

             reply	other threads:[~2023-06-08 23:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08 23:57 Yilkal Argaw [this message]
2023-06-09  6:22 ` Adding some convenience functions to color.el Philip Kaludercic
2023-06-09  6:55 ` Eli Zaretskii
2023-06-09  7:26   ` Yilkal Argaw
2023-06-09  7:34     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJddU=rZHpYo1w0m2hrdvO57T5c7mN8xm6oTqLmN9nFYqwwWyw@mail.gmail.com' \
    --to=yilkalargawworkneh@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).