summaryrefslogtreecommitdiff
path: root/pywal/util.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2020-01-24 08:26:06 +0200
committerDylan Araps <dylan.araps@gmail.com>2020-01-24 08:26:06 +0200
commit42ad8f014dfe11defe094a3ce33b60f7ec27b83b (patch)
treedcfb8a63a7e23a8bcf6bbdbc4c18bed563459148 /pywal/util.py
parent11758b4548c3b696769f307d132348eaf17d5efe (diff)
parentdb48957bde740e68dc64ceafef4e62ddc7018c6a (diff)
Merge branch 'master' of github.com:dylanaraps/pywal
Diffstat (limited to 'pywal/util.py')
-rw-r--r--pywal/util.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/pywal/util.py b/pywal/util.py
index e4b146a..cd6628a 100644
--- a/pywal/util.py
+++ b/pywal/util.py
@@ -5,10 +5,11 @@ import colorsys
import json
import logging
import os
+import platform
+import re
import shutil
import subprocess
import sys
-import platform
class Color:
@@ -35,7 +36,7 @@ class Color:
def rgba(self):
"""Convert a hex color to rgba."""
return "rgba(%s,%s,%s,%s)" % (*hex_to_rgb(self.hex_color),
- int(self.alpha_num)/100)
+ int(self.alpha_num) / 100)
@property
def alpha(self):
@@ -57,6 +58,21 @@ class Color:
"""Strip '#' from color."""
return self.hex_color[1:]
+ def lighten(self, percent):
+ """Lighten color by percent"""
+ percent = float(re.sub(r'[\D\.]', '', str(percent)))
+ return Color(lighten_color(self.hex_color, percent / 100))
+
+ def darken(self, percent):
+ """Darken color by percent"""
+ percent = float(re.sub(r'[\D\.]', '', str(percent)))
+ return Color(darken_color(self.hex_color, percent / 100))
+
+ def saturate(self, percent):
+ """Saturate a color"""
+ percent = float(re.sub(r'[\D\.]', '', str(percent)))
+ return Color(saturate_color(self.hex_color, percent / 100))
+
def read_file(input_file):
"""Read data from a file and trim newlines."""
@@ -156,11 +172,11 @@ def blend_color(color, color2):
def saturate_color(color, amount):
"""Saturate a hex color."""
r, g, b = hex_to_rgb(color)
- r, g, b = [x/255.0 for x in (r, g, b)]
+ r, g, b = [x / 255.0 for x in (r, g, b)]
h, l, s = colorsys.rgb_to_hls(r, g, b)
s = amount
r, g, b = colorsys.hls_to_rgb(h, l, s)
- r, g, b = [x*255.0 for x in (r, g, b)]
+ r, g, b = [x * 255.0 for x in (r, g, b)]
return rgb_to_hex((int(r), int(g), int(b)))