solarized-emacs

a fork of Bozhidar Batsov's solarized-emacs
git clone https://git.trogloxene.org/solarized-emacs.git
Log | Files | Refs | README

commit 4d2c482e4204c1e45013751823b9db2ee9deb460
parent 4b7b12fdb2a1762162d9dc4d9a48ae098923b8f6
Author: Thomas Frössman <thomasf@jossystem.se>
Date:   Sat,  5 Apr 2014 02:55:17 +0200

add color maniupulation functions

Diffstat:
Msolarized-theme-pkg.el | 3++-
Msolarized.el | 35+++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/solarized-theme-pkg.el b/solarized-theme-pkg.el @@ -1,4 +1,5 @@ (define-package "solarized-theme" "1.0.0" - "The Solarized color theme, ported to Emacs.") + "The Solarized color theme, ported to Emacs." + '("dash" "2.6.0")) diff --git a/solarized.el b/solarized.el @@ -104,6 +104,41 @@ Also affects `linum-mode' background." :type 'number :group 'solarized) +(defun solarized-color-name-to-rgb (color &optional frame) + "Convert COLOR string to a list of normalized RGB components. +COLOR should be a color name (e.g. \"white\") or an RGB triplet +string (e.g. \"#ff12ec\"). + +Normally the return value is a list of three floating-point +numbers, (RED GREEN BLUE), each between 0.0 and 1.0 inclusive. + +Optional argument FRAME specifies the frame where the color is to be +displayed. If FRAME is omitted or nil, use the selected frame. +If FRAME cannot display COLOR, return nil." + ;; `colors-values' maximum value is either 65535 or 65280 depending on the + ;; display system. So we use a white conversion to get the max value. + (let ((valmax (float (car (color-values "#ffffff"))))) + (mapcar (lambda (x) (/ x valmax)) (color-values color frame)))) + +(defun solarized-color-rgb-to-hex (red green blue) + "Return hexadecimal notation for the color RED GREEN BLUE. +RED, GREEN, and BLUE should be numbers between 0.0 and 1.0, inclusive." + (format "#%02x%02x%02x" + (* red 255) (* green 255) (* blue 255))) + +(defun solarized-color-blend (color1 color2 alpha) + "Blends COLOR1 onto COLOR2 with ALPHA. + +COLOR1 and COLOR2 should be color names (e.g. \"white\") or RGB +triplet strings (e.g. \"#ff12ec\"). + +Alpha should be a float between 0 and 1." + (apply 'solarized-color-rgb-to-hex + (-zip-with '(lambda (it other) + (+ (* alpha it) (* other (- 1 alpha)))) + (solarized-color-name-to-rgb color1) + (solarized-color-name-to-rgb color2)))) + (defun create-solarized-theme (variant theme-name &optional childtheme) "Create a VARIANT of the theme named THEME-NAME.