Update literate config
This commit is contained in:
parent
27362d8037
commit
8cd66e3b43
58
huepaper.org
58
huepaper.org
@ -1,15 +1,11 @@
|
|||||||
* huepaper
|
* huepaper
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:header-args: :tangle huepaper_tangled.py :shebang "#!/usr/bin/env python"
|
:header-args: :tangle huepaper.py :shebang "#!/usr/bin/env python"
|
||||||
:END:
|
:END:
|
||||||
|
|
||||||
This is the literate programming file for =huepaper.py=.
|
This is the literate programming file for =huepaper.py=.
|
||||||
To export it, open it in *Emacs* and *tangle* it.
|
To export it, open it in *Emacs* and *tangle* it.
|
||||||
|
|
||||||
** TODO Update to new code
|
|
||||||
|
|
||||||
Somehow old code was copied in here. Fix it!
|
|
||||||
|
|
||||||
** Imports
|
** Imports
|
||||||
|
|
||||||
huepaper is mainly based on two libraries.
|
huepaper is mainly based on two libraries.
|
||||||
@ -24,8 +20,30 @@ huepaper is mainly based on two libraries.
|
|||||||
from PIL import Image, ImageDraw, ImageOps
|
from PIL import Image, ImageDraw, ImageOps
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
** Logo
|
||||||
|
|
||||||
|
The logo of huepaper is printed on startup.
|
||||||
|
|
||||||
|
#+BEGIN_SRC python
|
||||||
|
def print_logo():
|
||||||
|
logo = '''
|
||||||
|
.lk.
|
||||||
|
cO.
|
||||||
|
cO.;:lc. ,c. .cc .,',c; .,c.;coc. ;,.,c. ':l.:lo: '',:c. '::.lo.
|
||||||
|
cO' kd .O; dO ,x...,Ox cO; lO: ;x xk OO. .kO. x;...x0' 0x. .
|
||||||
|
cO. xx .O; dO ko...... :O. Ox .,..xO kk ;0;;0...... 0d
|
||||||
|
cO. xx .O; xO dO. .. :O. .O; dk xO kk :O.'0o , 0d
|
||||||
|
.dk, .kk. okc;,ox' ckxllc. :Oc'.,l' oOl;'dO:. kO;..:l. ,xOolc; ,Ox.
|
||||||
|
:O. kk
|
||||||
|
lO, OO
|
||||||
|
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00O0000000000000000;
|
||||||
|
''';
|
||||||
|
print(logo)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
** Base color
|
** Base color
|
||||||
|
|
||||||
|
|
||||||
Every huepaper has a base color.
|
Every huepaper has a base color.
|
||||||
It is used to calculate the final colors.
|
It is used to calculate the final colors.
|
||||||
|
|
||||||
@ -236,27 +254,24 @@ Already existing files are only overwritten if the user wants to.
|
|||||||
|
|
||||||
** Main
|
** Main
|
||||||
|
|
||||||
|
In the main routine, the arguments are parsed and the image is created.
|
||||||
|
|
||||||
#+BEGIN_SRC python
|
#+BEGIN_SRC python
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
global width, height, max_hue, sat_min, sat_max, lum_min, lum_max
|
global width, height, max_hue, sat_min, sat_max, lum_min, lum_max
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
*** Arguments
|
|
||||||
|
|
||||||
The script has various arguments which are used to create the huepaper.
|
|
||||||
|
|
||||||
#+BEGIN_SRC python
|
|
||||||
parser = argparse.ArgumentParser(description = 'Create wallpapers based on color hues.')
|
parser = argparse.ArgumentParser(description = 'Create wallpapers based on color hues.')
|
||||||
parser.add_argument('-W', '--width', default = 1920, type = int, help = 'width of wallpaper (defaul: 1920)')
|
parser.add_argument('-W', '--width', default = 1920, type = int, help = 'width of huepaper (default: 1920)')
|
||||||
parser.add_argument('-H', '--height', default = 1080, type = int, help = 'height of wallpaper (default: 1080)')
|
parser.add_argument('-H', '--height', default = 1080, type = int, help = 'height of huepaper (default: 1080)')
|
||||||
parser.add_argument('-c', '--color', help = 'color, the wallpaper is generated from (uses a random color if not given)')
|
parser.add_argument('-c', '--color', help = 'color, the huepaper is generated from (uses a random color if not given)')
|
||||||
parser.add_argument('-p', '--preview', action = 'store_true', help = 'preview wallpaper')
|
parser.add_argument('-p', '--preview', action = 'store_true', help = 'preview huepaper')
|
||||||
parser.add_argument('-o', '--output', help = 'file where to save the wallpaper to (default: None)')
|
parser.add_argument('-o', '--output', help = 'file where to save the huepaper to (default: None)')
|
||||||
parser.add_argument('-l', '--lines', nargs = '?', const = 0.1, type = float, help = 'include one to three random lines in base color with given opacity in range [0, 1] (default: 0.1)')
|
parser.add_argument('-l', '--lines', nargs = '?', const = 0.3, type = float, help = 'include one to three random lines in base color with given opacity in range [0, 1] (default: 0.3)')
|
||||||
parser.add_argument('-lb', '--lines_bright', nargs = '?', const = 0.1, type = float, help = 'include one to three bright random lines with given opacity in range [0, 1] (default: 0.1)')
|
parser.add_argument('-lb', '--lines_bright', nargs = '?', const = 0.1, type = float, help = 'include one to three bright random lines with given opacity in range [0, 1] (default: 0.1)')
|
||||||
parser.add_argument('-ld', '--lines_dark', nargs = '?', const = 0.1, type = float, help = 'include one to three dark random lines with given opacity in range [0, 1] (default: 0.1)')
|
parser.add_argument('-ld', '--lines_dark', nargs = '?', const = 0.1, type = float, help = 'include one to three dark random lines with given opacity in range [0, 1] (default: 0.1)')
|
||||||
parser.add_argument('-P', '--pixelate', help = "pixelate image (e.g. 42x42)")
|
parser.add_argument('-P', '--pixelate', help = "pixelate image (e.g. 42x42)")
|
||||||
parser.add_argument('-e', '--emblem', help = 'emblem to add in the center of the wallpaper')
|
parser.add_argument('-e', '--emblem', help = 'emblem to add in the center of the huepaper')
|
||||||
parser.add_argument('-hue', default = 0.1, type = float, help = 'maximum hue to differ from given color in range [0, 1] (default: 0.1)')
|
parser.add_argument('-hue', default = 0.1, type = float, help = 'maximum hue to differ from given color in range [0, 1] (default: 0.1)')
|
||||||
parser.add_argument('-smin', default = 0.2, type = float, help = 'minimum satisfaction for colors in range [0, 1] (default: 0.2)')
|
parser.add_argument('-smin', default = 0.2, type = float, help = 'minimum satisfaction for colors in range [0, 1] (default: 0.2)')
|
||||||
parser.add_argument('-smax', default = 1.0, type = float, help = 'maximum satisfaction for colors in range [0, 1] (default: 1.0)')
|
parser.add_argument('-smax', default = 1.0, type = float, help = 'maximum satisfaction for colors in range [0, 1] (default: 1.0)')
|
||||||
@ -291,11 +306,8 @@ The script has various arguments which are used to create the huepaper.
|
|||||||
py = int(values[1])
|
py = int(values[1])
|
||||||
except:
|
except:
|
||||||
parser.error('Pixelation value must be set in form: 42x42')
|
parser.error('Pixelation value must be set in form: 42x42')
|
||||||
#+END_SRC
|
|
||||||
|
|
||||||
*** Routine
|
print_logo()
|
||||||
|
|
||||||
#+BEGIN_SRC python
|
|
||||||
base_color = get_base_color(color)
|
base_color = get_base_color(color)
|
||||||
c1, c2, c3, c4 = create_colors(base_color)
|
c1, c2, c3, c4 = create_colors(base_color)
|
||||||
image = create_base_image(c1, c2, c3, c4)
|
image = create_base_image(c1, c2, c3, c4)
|
||||||
@ -313,6 +325,8 @@ The script has various arguments which are used to create the huepaper.
|
|||||||
if emblem:
|
if emblem:
|
||||||
image = add_emblem(image, emblem)
|
image = add_emblem(image, emblem)
|
||||||
|
|
||||||
|
image.mode = 'RGB'
|
||||||
|
|
||||||
if preview:
|
if preview:
|
||||||
image.show()
|
image.show()
|
||||||
if not output:
|
if not output:
|
||||||
|
22
huepaper.py
22
huepaper.py
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os.path
|
import os.path
|
||||||
import random
|
import random
|
||||||
@ -7,7 +6,6 @@ import sys
|
|||||||
from colour import Color
|
from colour import Color
|
||||||
from PIL import Image, ImageDraw, ImageOps
|
from PIL import Image, ImageDraw, ImageOps
|
||||||
|
|
||||||
|
|
||||||
def print_logo():
|
def print_logo():
|
||||||
logo = '''
|
logo = '''
|
||||||
.lk.
|
.lk.
|
||||||
@ -23,7 +21,6 @@ def print_logo():
|
|||||||
''';
|
''';
|
||||||
print(logo)
|
print(logo)
|
||||||
|
|
||||||
# Get base color
|
|
||||||
def get_base_color(color_string = None):
|
def get_base_color(color_string = None):
|
||||||
|
|
||||||
# If no color string is given, create a random color
|
# If no color string is given, create a random color
|
||||||
@ -44,8 +41,6 @@ def get_base_color(color_string = None):
|
|||||||
|
|
||||||
return base_color
|
return base_color
|
||||||
|
|
||||||
|
|
||||||
# Create colors from a base color
|
|
||||||
def create_colors(base_color):
|
def create_colors(base_color):
|
||||||
|
|
||||||
colors = []
|
colors = []
|
||||||
@ -71,8 +66,6 @@ def create_colors(base_color):
|
|||||||
|
|
||||||
return tuple(colors)
|
return tuple(colors)
|
||||||
|
|
||||||
|
|
||||||
# Create base image from four colors, width and height
|
|
||||||
# c1 - top left
|
# c1 - top left
|
||||||
# c2 - top right
|
# c2 - top right
|
||||||
# c3 - bottom right
|
# c3 - bottom right
|
||||||
@ -102,8 +95,6 @@ def create_base_image(c1, c2, c3, c4):
|
|||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
# Add lines to an image
|
|
||||||
def add_lines(image, color):
|
def add_lines(image, color):
|
||||||
|
|
||||||
line_image = Image.new('RGBA', (width, height), (0, 0, 0, 0))
|
line_image = Image.new('RGBA', (width, height), (0, 0, 0, 0))
|
||||||
@ -135,8 +126,6 @@ def add_lines(image, color):
|
|||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
# Add pixelation to image
|
|
||||||
def add_pixelation(image, x, y):
|
def add_pixelation(image, x, y):
|
||||||
|
|
||||||
image = image.resize((x, y))
|
image = image.resize((x, y))
|
||||||
@ -144,8 +133,6 @@ def add_pixelation(image, x, y):
|
|||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
# Add emblem to an image from a filepath
|
|
||||||
def add_emblem(image, filepath):
|
def add_emblem(image, filepath):
|
||||||
|
|
||||||
# Load image
|
# Load image
|
||||||
@ -166,8 +153,6 @@ def add_emblem(image, filepath):
|
|||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
# Save image to filepath
|
|
||||||
def save_image(filepath, image):
|
def save_image(filepath, image):
|
||||||
|
|
||||||
save = True
|
save = True
|
||||||
@ -193,16 +178,10 @@ def save_image(filepath, image):
|
|||||||
else:
|
else:
|
||||||
filepath = input('Please enter new path where the wallpaper shall be saved: ')
|
filepath = input('Please enter new path where the wallpaper shall be saved: ')
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
Main
|
|
||||||
'''
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
global width, height, max_hue, sat_min, sat_max, lum_min, lum_max
|
global width, height, max_hue, sat_min, sat_max, lum_min, lum_max
|
||||||
|
|
||||||
# Initialize parser
|
|
||||||
parser = argparse.ArgumentParser(description = 'Create wallpapers based on color hues.')
|
parser = argparse.ArgumentParser(description = 'Create wallpapers based on color hues.')
|
||||||
parser.add_argument('-W', '--width', default = 1920, type = int, help = 'width of huepaper (default: 1920)')
|
parser.add_argument('-W', '--width', default = 1920, type = int, help = 'width of huepaper (default: 1920)')
|
||||||
parser.add_argument('-H', '--height', default = 1080, type = int, help = 'height of huepaper (default: 1080)')
|
parser.add_argument('-H', '--height', default = 1080, type = int, help = 'height of huepaper (default: 1080)')
|
||||||
@ -249,7 +228,6 @@ def main():
|
|||||||
except:
|
except:
|
||||||
parser.error('Pixelation value must be set in form: 42x42')
|
parser.error('Pixelation value must be set in form: 42x42')
|
||||||
|
|
||||||
# Main routine
|
|
||||||
print_logo()
|
print_logo()
|
||||||
base_color = get_base_color(color)
|
base_color = get_base_color(color)
|
||||||
c1, c2, c3, c4 = create_colors(base_color)
|
c1, c2, c3, c4 = create_colors(base_color)
|
||||||
|
Loading…
Reference in New Issue
Block a user