|
@ -1,7 +1,7 @@ |
|
|
import math |
|
|
import math |
|
|
|
|
|
|
|
|
# # Linear |
|
|
|
|
|
def diagonal(): |
|
|
def diagonal(): |
|
|
|
|
|
"""Draw a diagnal line from top left to bottom right""" |
|
|
def f (x, y, width, height, mark, blank): |
|
|
def f (x, y, width, height, mark, blank): |
|
|
if x == math.floor((y / float(height)) * width): |
|
|
if x == math.floor((y / float(height)) * width): |
|
|
return mark() |
|
|
return mark() |
|
@ -12,6 +12,7 @@ def diagonal(): |
|
|
|
|
|
|
|
|
# Cross |
|
|
# Cross |
|
|
def cross (): |
|
|
def cross (): |
|
|
|
|
|
"""Draw two diagonals""" |
|
|
def f (x, y, width, height, mark, blank): |
|
|
def f (x, y, width, height, mark, blank): |
|
|
pos = math.floor((y / float(height)) * width) |
|
|
pos = math.floor((y / float(height)) * width) |
|
|
|
|
|
|
|
@ -22,17 +23,20 @@ def cross (): |
|
|
return f |
|
|
return f |
|
|
|
|
|
|
|
|
def horizontal (position): |
|
|
def horizontal (position): |
|
|
|
|
|
"""Draw horizontal line at given Y position.""" |
|
|
def f (x, y, width, height, mark, blank): |
|
|
def f (x, y, width, height, mark, blank): |
|
|
return mark() if position == y else blank() |
|
|
return mark() if position == y else blank() |
|
|
return f |
|
|
return f |
|
|
|
|
|
|
|
|
def vertical (position): |
|
|
def vertical (position): |
|
|
|
|
|
"""Draw a vertical line at given X position.""" |
|
|
def f (x, y, width, height, mark, blank): |
|
|
def f (x, y, width, height, mark, blank): |
|
|
return mark() if position == x else blank() |
|
|
return mark() if position == x else blank() |
|
|
return f |
|
|
return f |
|
|
|
|
|
|
|
|
# Sinus |
|
|
# Sinus |
|
|
def sinus_vertical (period=0.2, amplitude=0.5, offset_t=0, offset=0): |
|
|
def sinus_vertical (period=0.2, amplitude=0.5, offset_t=0, offset=0): |
|
|
|
|
|
"""Draw a sinus shape vertically""" |
|
|
period = (period / (math.pi * 2)) |
|
|
period = (period / (math.pi * 2)) |
|
|
|
|
|
|
|
|
def f (x, y, width, height, mark, blank): |
|
|
def f (x, y, width, height, mark, blank): |
|
@ -42,6 +46,7 @@ def sinus_vertical (period=0.2, amplitude=0.5, offset_t=0, offset=0): |
|
|
return f |
|
|
return f |
|
|
|
|
|
|
|
|
def sinus_horizontal (period=0.2, amplitude=0.5, offset_t=0, offset=0): |
|
|
def sinus_horizontal (period=0.2, amplitude=0.5, offset_t=0, offset=0): |
|
|
|
|
|
"""Draw a sinus shape horizontally""" |
|
|
period = (period / (math.pi * 2)) |
|
|
period = (period / (math.pi * 2)) |
|
|
def f (x, y, width, height, mark, blank): |
|
|
def f (x, y, width, height, mark, blank): |
|
|
middle = (height - 1) * .5 |
|
|
middle = (height - 1) * .5 |
|
@ -51,7 +56,12 @@ def sinus_horizontal (period=0.2, amplitude=0.5, offset_t=0, offset=0): |
|
|
return f |
|
|
return f |
|
|
|
|
|
|
|
|
def image (path, threshold=128): |
|
|
def image (path, threshold=128): |
|
|
from PIL import Image |
|
|
"""Put marks based on a mask. Requires Pillow""" |
|
|
|
|
|
try: |
|
|
|
|
|
from PIL import Image |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
print('The image patter requires pillow to be installed.') |
|
|
|
|
|
exit() |
|
|
|
|
|
|
|
|
im = Image.open(path).convert('L') |
|
|
im = Image.open(path).convert('L') |
|
|
image_width, image_height = im.size |
|
|
image_width, image_height = im.size |
|
|