Update literate config
This commit is contained in:
parent
27362d8037
commit
8cd66e3b43
68
huepaper.org
68
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.
|
||||||
|
|
||||||
@ -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.
|
If no color is given, a random one is chosen.
|
||||||
|
|
||||||
#+BEGIN_SRC python
|
#+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 no color string is given, create a random color
|
||||||
if not color_string:
|
if not color_string:
|
||||||
@ -116,7 +134,7 @@ All other pixel colors are linear interpolated.
|
|||||||
# Create image
|
# Create image
|
||||||
image = Image.new('RGBA', (width, height))
|
image = Image.new('RGBA', (width, height))
|
||||||
pixels = image.load()
|
pixels = image.load()
|
||||||
|
|
||||||
for x in range(0, width):
|
for x in range(0, width):
|
||||||
for y in range(0, height):
|
for y in range(0, height):
|
||||||
pixels[x, y] = col(x / (width - 1), y / (height - 1))
|
pixels[x, y] = col(x / (width - 1), y / (height - 1))
|
||||||
@ -157,7 +175,7 @@ Vertical lines can be added on the side of the huepaper.
|
|||||||
|
|
||||||
# Add line image to input image
|
# Add line image to input image
|
||||||
image.alpha_composite(line_image, (0, 0))
|
image.alpha_composite(line_image, (0, 0))
|
||||||
|
|
||||||
return image
|
return image
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
@ -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)
|
||||||
@ -309,10 +321,12 @@ The script has various arguments which are used to create the huepaper.
|
|||||||
|
|
||||||
if pixelate:
|
if pixelate:
|
||||||
image = add_pixelation(image, px, py)
|
image = add_pixelation(image, px, py)
|
||||||
|
|
||||||
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:
|
||||||
@ -323,7 +337,7 @@ The script has various arguments which are used to create the huepaper.
|
|||||||
|
|
||||||
if output:
|
if output:
|
||||||
save_image(output, image)
|
save_image(output, image)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
34
huepaper.py
34
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,12 +41,10 @@ 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 = []
|
||||||
|
|
||||||
max_sat_diff = 0.1
|
max_sat_diff = 0.1
|
||||||
max_lum_diff = 0.1
|
max_lum_diff = 0.1
|
||||||
|
|
||||||
@ -62,7 +57,7 @@ def create_colors(base_color):
|
|||||||
|
|
||||||
tmp_sat = base_color.saturation + random.uniform(-max_sat_diff, max_sat_diff)
|
tmp_sat = base_color.saturation + random.uniform(-max_sat_diff, max_sat_diff)
|
||||||
tmp_sat = min(sat_max, max(sat_min, tmp_sat))
|
tmp_sat = min(sat_max, max(sat_min, tmp_sat))
|
||||||
|
|
||||||
tmp_lum = base_color.luminance + random.uniform(-max_lum_diff, max_lum_diff)
|
tmp_lum = base_color.luminance + random.uniform(-max_lum_diff, max_lum_diff)
|
||||||
tmp_lum = min(lum_max, max(lum_min, tmp_lum))
|
tmp_lum = min(lum_max, max(lum_min, tmp_lum))
|
||||||
|
|
||||||
@ -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
|
||||||
@ -95,15 +88,13 @@ def create_base_image(c1, c2, c3, c4):
|
|||||||
# Create image
|
# Create image
|
||||||
image = Image.new('RGBA', (width, height))
|
image = Image.new('RGBA', (width, height))
|
||||||
pixels = image.load()
|
pixels = image.load()
|
||||||
|
|
||||||
for x in range(0, width):
|
for x in range(0, width):
|
||||||
for y in range(0, height):
|
for y in range(0, height):
|
||||||
pixels[x, y] = col(x / (width - 1), y / (height - 1))
|
pixels[x, y] = col(x / (width - 1), y / (height - 1))
|
||||||
|
|
||||||
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))
|
||||||
@ -132,11 +123,9 @@ def add_lines(image, color):
|
|||||||
|
|
||||||
# Add line image to input image
|
# Add line image to input image
|
||||||
image.alpha_composite(line_image, (0, 0))
|
image.alpha_composite(line_image, (0, 0))
|
||||||
|
|
||||||
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)
|
||||||
@ -264,7 +242,7 @@ def main():
|
|||||||
|
|
||||||
if pixelate:
|
if pixelate:
|
||||||
image = add_pixelation(image, px, py)
|
image = add_pixelation(image, px, py)
|
||||||
|
|
||||||
if emblem:
|
if emblem:
|
||||||
image = add_emblem(image, emblem)
|
image = add_emblem(image, emblem)
|
||||||
|
|
||||||
@ -280,7 +258,7 @@ def main():
|
|||||||
|
|
||||||
if output:
|
if output:
|
||||||
save_image(output, image)
|
save_image(output, image)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user