Update literate config

This commit is contained in:
Denis Lehmann 2020-09-13 14:28:25 +02:00
parent 27362d8037
commit 8cd66e3b43
2 changed files with 47 additions and 55 deletions

View File

@ -1,15 +1,11 @@
* huepaper
:PROPERTIES:
:header-args: :tangle huepaper_tangled.py :shebang "#!/usr/bin/env python"
:header-args: :tangle huepaper.py :shebang "#!/usr/bin/env python"
:END:
This is the literate programming file for =huepaper.py=.
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
huepaper is mainly based on two libraries.
@ -24,8 +20,30 @@ huepaper is mainly based on two libraries.
from PIL import Image, ImageDraw, ImageOps
#+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
Every huepaper has a base color.
It is used to calculate the final colors.
@ -33,7 +51,7 @@ If a base color is given by the user, it can have every format, Colour supports.
If no color is given, a random one is chosen.
#+BEGIN_SRC python
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 not color_string:
@ -236,27 +254,24 @@ Already existing files are only overwritten if the user wants to.
** Main
In the main routine, the arguments are parsed and the image is created.
#+BEGIN_SRC python
def main():
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.add_argument('-W', '--width', default = 1920, type = int, help = 'width of wallpaper (defaul: 1920)')
parser.add_argument('-H', '--height', default = 1080, type = int, help = 'height of wallpaper (default: 1080)')
parser.add_argument('-c', '--color', help = 'color, the wallpaper is generated from (uses a random color if not given)')
parser.add_argument('-p', '--preview', action = 'store_true', help = 'preview wallpaper')
parser.add_argument('-o', '--output', help = 'file where to save the wallpaper 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('-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('-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 huepaper')
parser.add_argument('-o', '--output', help = 'file where to save the huepaper to (default: None)')
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('-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('-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('-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)')
@ -291,11 +306,8 @@ The script has various arguments which are used to create the huepaper.
py = int(values[1])
except:
parser.error('Pixelation value must be set in form: 42x42')
#+END_SRC
*** Routine
#+BEGIN_SRC python
print_logo()
base_color = get_base_color(color)
c1, c2, c3, c4 = create_colors(base_color)
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:
image = add_emblem(image, emblem)
image.mode = 'RGB'
if preview:
image.show()
if not output:

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
import argparse
import os.path
import random
@ -7,7 +6,6 @@ import sys
from colour import Color
from PIL import Image, ImageDraw, ImageOps
def print_logo():
logo = '''
.lk.
@ -23,7 +21,6 @@ def print_logo():
''';
print(logo)
# Get base color
def get_base_color(color_string = None):
# If no color string is given, create a random color
@ -44,8 +41,6 @@ def get_base_color(color_string = None):
return base_color
# Create colors from a base color
def create_colors(base_color):
colors = []
@ -71,8 +66,6 @@ def create_colors(base_color):
return tuple(colors)
# Create base image from four colors, width and height
# c1 - top left
# c2 - top right
# c3 - bottom right
@ -102,8 +95,6 @@ def create_base_image(c1, c2, c3, c4):
return image
# Add lines to an image
def add_lines(image, color):
line_image = Image.new('RGBA', (width, height), (0, 0, 0, 0))
@ -135,8 +126,6 @@ def add_lines(image, color):
return image
# Add pixelation to image
def add_pixelation(image, x, y):
image = image.resize((x, y))
@ -144,8 +133,6 @@ def add_pixelation(image, x, y):
return image
# Add emblem to an image from a filepath
def add_emblem(image, filepath):
# Load image
@ -166,8 +153,6 @@ def add_emblem(image, filepath):
return image
# Save image to filepath
def save_image(filepath, image):
save = True
@ -193,16 +178,10 @@ def save_image(filepath, image):
else:
filepath = input('Please enter new path where the wallpaper shall be saved: ')
'''
Main
'''
def main():
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.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)')
@ -249,7 +228,6 @@ def main():
except:
parser.error('Pixelation value must be set in form: 42x42')
# Main routine
print_logo()
base_color = get_base_color(color)
c1, c2, c3, c4 = create_colors(base_color)