Commit 10ddf5c0 authored by gijs's avatar gijs
Browse files

First commit

parents
Pipeline #470 canceled with stages
#!/usr/bin/env python3
#!/usr/bin/env python3
import utils
import patterns
import marks
\ No newline at end of file
# -*- coding: utf-8 -*-
from utils import make_lines, merge, print_lines, rotate, visit, visit_horizontal
from patterns import diagonal, horizontal, vertical, sinus_horizontal, sinus_vertical, image
from marks import random_mark, sequence_mark, space
from random import choice, random
import math
# marks = ['┼', '│', '░', '▓', 'X', '■', '≡', '·', '¦', ' ']
# blank = ' '
width = 75
height = 50
mark = sequence_mark('O.P.E.N D.E.S.I.G.N C.O.U.R.S.E ')
layers = []
# layers.append(visit(make_lines(width, height), image('blobs-small.png'), mark, space(' ')))
for offset in range(-50, 50, 15):
lines = [[] for l in range(height)]
sinus = sinus_vertical(period=50, amplitude=25, offset=offset, offset_t=random())
layers.append(visit(make_lines(width, height), sinus, sequence_mark(' K A S K G E N T '), space()))
for offset in range(-43, 57, 15):
lines = [[] for l in range(height)]
sinus = sinus_vertical(period=40, amplitude=10, offset=offset, offset_t=.5+random())
layers.append(visit(make_lines(width, height), sinus, mark, space()))
print_lines(merge(width, height, space()(), layers))
# for line in overlay(50, 50, ' ', [rotate(merged), merged]):
# stdout.write('{}\n'.format(''.join(line)))
# sinus = sinus_horizontal(period=30, amplitude=8)
# for x in range(width):
# for y in range(height):
# lines[y].append(sinus(x, y, width, height, mark, space()))
# for line in lines:
# stdout.write('{}\n'.format(''.join(line)))
# lines = [[draw(x, y, marks) for x in range(width)] for y in range(height)]
# sys.sdout.write('\n'.join([''.join(line) for line in lines]))
# sys.sdout.write('\n'.join([''.join([draw(x, y, marks) for x in range(width)]) for y in range(height)]))
from random import choice
def random (marks=['']):
def func ():
return choice(marks)
return func
def sentence (text):
chars = list(text)
def f():
char = chars.pop(0)
chars.append(char)
return char
return f
def single (char):
def f():
return char
return f
def space (space=' '):
return single(space)
import math
# # Linear
def diagonal():
def f (x, y, width, height, mark, blank):
if x == math.floor((y / float(height)) * width):
return mark()
else:
return blank()
return f
# Cross
def cross ():
def f (x, y, width, height, mark, blank):
pos = math.floor((y / float(height)) * width)
if x == pos or (width - 1) - pos == x:
return mark()
else:
return blank()
return f
def horizontal (position):
def f (x, y, width, height, mark, blank):
return mark() if position == y else blank()
return f
def vertical (position):
def f (x, y, width, height, mark, blank):
return mark() if position == x else blank()
return f
# Sinus
def sinus_vertical (period=0.2, amplitude=0.5, offset_t=0, offset=0):
period = (period / (math.pi * 2))
def f (x, y, width, height, mark, blank):
middle = (width - 1) * .5
to_mark = math.floor(middle + math.sin(offset_t + y / period) * amplitude)
return mark() if (x + offset) == to_mark else blank()
return f
def sinus_horizontal (period=0.2, amplitude=0.5, offset_t=0, offset=0):
period = (period / (math.pi * 2))
def f (x, y, width, height, mark, blank):
middle = (height - 1) * .5
to_mark = math.floor(middle + math.sin(offset_t + x / period) * amplitude)
return mark() if y + offset == to_mark else blank()
return f
def image (path, threshold=128):
from PIL import Image
im = Image.open(path).convert('L')
image_width, image_height = im.size
pixels = im.load()
def f (x, y, width, height, mark, blank):
if x < image_width and y < image_height:
if pixels[x, y] < threshold:
return mark()
return blank()
return f
from sys import stdout
def rotate(layer):
new_width = len(layer)
new_height = len(layer[0])
rotated = [['' for x in range(new_width)] for l in range(new_height)]
for y in range(len(layer)):
for x in range(len(layer[y])):
rotated[x][y] = layer[y][x]
return rotated
def merge(width, height, space_char, layers):
output = [[space_char for x in range(width)] for y in range(height)]
for layer in layers:
for y in range(height):
for x in range(width):
if layer[y][x] != space_char:
output[y][x] = layer[y][x]
return output
# Make a multidimensional array
# with the given dimensions
def make_lines (width, height, fill_char = ''):
return [[ fill_char for _ in range(width) ] for __ in range(height)]
def visit (lines, callback, mark, blank):
height = len(lines)
width = len(lines[0])
for y in range(height):
for x in range(width):
lines[y][x] = callback(x, y, width, height, mark, blank)
return lines
def visit_horizontal (lines, callback, mark, blank):
height = len(lines)
width = len(lines[0])
for x in range(width):
for y in range(height):
lines[y][x] = callback(x, y, width, height, mark, blank)
return lines
def print_lines (lines):
for line in lines:
stdout.write('{}\n'.format(''.join(line)))
\ No newline at end of file
#!/usr/bin/env python3
"""
Uses an image as a guide to draw either blanks or
mark chars. In this case with the char '+'.
"""
from asciiWriter.patterns import image
from asciiWriter.utils import make_lines, visit, print_lines
from asciiWriter.marks import single, space
width = 75
height = 75
# Where to find the image
image_path = 'images/blobs-small.png'
# Construct the pattern
image_pattern = image(image_path)
# Set the marker, in this case the character '+'
mark = single('+')
# Define what to use on a blank space, as a variation you coul use: single('*')
blank = space()
# Make a canvas
lines = make_lines(width, height)
# Draw the picture
result = visit(lines, image_pattern, mark, blank)
# Print the result
print_lines(result)
\ No newline at end of file
#!/usr/bin/env python3
from asciiWriter.patterns import image
from asciiWriter.utils import make_lines, visit, print_lines
from asciiWriter.marks import random, single
width = 75
height = 75
# Where to find the image
image_path = 'images/blobs-small.png'
# Construct the pattern
image_pattern = image(image_path)
# Set the marker, in this case it makes a random selection from
# the list: +, *, $, #, ,
mark = random(['+', '*', '$', '#', ' ', ' '])
# Define what to use on a blank space, as a variation you coul use: single('*')
blank = single()
# Make a canvas
lines = make_lines(width, height)
# Draw the picture
result = visit(lines, image_pattern, mark, blank)
# Print the result
print_lines(result)
\ No newline at end of file
#!/usr/bin/env python3
"""
Same as image_sentence.py, but rotates the result.
Uses an image to define where to put chars.
In this case with the sentence/word ASCII
"""
from asciiWriter.patterns import image
from asciiWriter.utils import make_lines, visit, print_lines, rotate
from asciiWriter.marks import sentence, single
width = 75
height = 75
# Where to find the image
image_path = 'images/blobs-small.png'
# Construct the pattern
image_pattern = image(image_path)
# Set the marker, in this case a sentence
mark = sentence('ASCII ')
# Define what to use on a blank space, as a variation you coul use: single('*')
blank = single(' ')
# Make a canvas
lines = make_lines(width, height)
# Draw the picture
result = visit(lines, image_pattern, mark, blank)
# Rotate the canvas
result = rotate(result)
# Print the result
print_lines(result)
\ No newline at end of file
#!/usr/bin/env python3
"""
Uses an image to define where to put chars.
In this case with the sentence/word ASCII
"""
from asciiWriter.patterns import image
from asciiWriter.utils import make_lines, visit, print_lines
from asciiWriter.marks import sentence, space
width = 75
height = 75
# Where to find the image
image_path = 'images/blobs-small.png'
image_path = 'images/shapes.png'
# Construct the pattern
image_pattern = image(image_path)
# Set the marker, in this case a sentence
mark = sentence('U.R.S O.P.E.N. D.E.S.I.G.N C.O.')
# Define what to use on a blank space, as a variation you coul use: single('*')
blank = space()
# Make a canvas
lines = make_lines(width, height)
# Draw the picture
result = visit(lines, image_pattern, mark, blank)
# Print the result
print_lines(result)
\ No newline at end of file
#!/usr/bin/env python3
"""
Draws a single, vertical line
"""
from asciiWriter.patterns import vertical
from asciiWriter.utils import make_lines, visit, print_lines
from asciiWriter.marks import sentence, space
# Set the canvas
width = 75
height = 75
# Define the line, most importantly it's position
pattern = vertical(20)
# We're going to fill the line with a text
mark = sentence('OPEN DESIGN COURSE ')
# Set the character for the 'blank' space
blank = space()
# Make a canvas
lines = make_lines(width, height)
# Draw the result
result = visit(lines, pattern, mark, blank)
# Print the result
print_lines(result)
\ No newline at end of file
#!/usr/bin/env python3
"""
Draws a single just like line.py but does so
using a 'random' character
"""
from asciiWriter.patterns import vertical
from asciiWriter.utils import make_lines, visit, print_lines
from asciiWriter.marks import random, space
# Set the canvas
width = 75
height = 75
# Define the line, most importantly it's position
image_pattern = vertical(20)
# We're going to fill the line with random selections
# from the '%$&@!*' chars
mark = random('%$&@!*')
# Set the character for the 'blank' space
blank = space()
# Make a canvas
lines = make_lines(width, height)
# Draw the result
result = visit(lines, image_pattern, mark, blank)
# Print the result
print_lines(result)
\ No newline at end of file
#!/usr/bin/env python3
"""
Draws lines like line.py, but draws more than one
"""
from asciiWriter.patterns import vertical
from asciiWriter.utils import make_lines, visit, print_lines, merge
from asciiWriter.marks import sentence, space
# Set the canvas
width = 75
height = 75
# We are going to draw multiple lines and collect them
# in a list named 'layers'
layers = []
# Set the position of the line, do this in a loop
# from 10 to 75 in steps of then
for x in range(10, 75, 10):
# Define the line, x will start at 10 and grow in steps of 10
image_pattern = vertical(x)
# Fill the line with the sentence 'OPEN DESIGN COURSE '
mark = sentence('OPEN DESIGN COURSE ')
# Set the blank space
blank = space()
# Make a canvas
lines = make_lines(width, height)
# Make a layer with the line
layer = visit(lines, image_pattern, mark, blank)
# Add the layer to the list of layers
layers.append(layer)
# Merge the list of layers into a single layer
result = merge(width, height, blank(), layers)
# Print the result
print_lines(result)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment