commit 1b6648c8582ea230a37ceca56959afef108fd82d Author: manetta Date: Mon Dec 23 15:00:49 2019 +0100 first commit :) diff --git a/asciiWriter/__init__.py b/asciiWriter/__init__.py new file mode 100644 index 0000000..63f77b6 --- /dev/null +++ b/asciiWriter/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python3 + diff --git a/asciiWriter/__pycache__/__init__.cpython-36.pyc b/asciiWriter/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..cade769 Binary files /dev/null and b/asciiWriter/__pycache__/__init__.cpython-36.pyc differ diff --git a/asciiWriter/__pycache__/__init__.cpython-37.pyc b/asciiWriter/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..64f044f Binary files /dev/null and b/asciiWriter/__pycache__/__init__.cpython-37.pyc differ diff --git a/asciiWriter/__pycache__/marks.cpython-36.pyc b/asciiWriter/__pycache__/marks.cpython-36.pyc new file mode 100644 index 0000000..9a0e7bd Binary files /dev/null and b/asciiWriter/__pycache__/marks.cpython-36.pyc differ diff --git a/asciiWriter/__pycache__/marks.cpython-37.pyc b/asciiWriter/__pycache__/marks.cpython-37.pyc new file mode 100644 index 0000000..cb0896c Binary files /dev/null and b/asciiWriter/__pycache__/marks.cpython-37.pyc differ diff --git a/asciiWriter/__pycache__/patterns.cpython-36.pyc b/asciiWriter/__pycache__/patterns.cpython-36.pyc new file mode 100644 index 0000000..3e0edae Binary files /dev/null and b/asciiWriter/__pycache__/patterns.cpython-36.pyc differ diff --git a/asciiWriter/__pycache__/patterns.cpython-37.pyc b/asciiWriter/__pycache__/patterns.cpython-37.pyc new file mode 100644 index 0000000..b8d5e48 Binary files /dev/null and b/asciiWriter/__pycache__/patterns.cpython-37.pyc differ diff --git a/asciiWriter/__pycache__/utils.cpython-36.pyc b/asciiWriter/__pycache__/utils.cpython-36.pyc new file mode 100644 index 0000000..9e10c96 Binary files /dev/null and b/asciiWriter/__pycache__/utils.cpython-36.pyc differ diff --git a/asciiWriter/__pycache__/utils.cpython-37.pyc b/asciiWriter/__pycache__/utils.cpython-37.pyc new file mode 100644 index 0000000..9300082 Binary files /dev/null and b/asciiWriter/__pycache__/utils.cpython-37.pyc differ diff --git a/asciiWriter/asciiWriter.py b/asciiWriter/asciiWriter.py new file mode 100644 index 0000000..917c502 --- /dev/null +++ b/asciiWriter/asciiWriter.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +import utils +import patterns +import marks \ No newline at end of file diff --git a/asciiWriter/draw.py b/asciiWriter/draw.py new file mode 100644 index 0000000..5dee52e --- /dev/null +++ b/asciiWriter/draw.py @@ -0,0 +1,49 @@ +# -*- 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)])) diff --git a/asciiWriter/marks.py b/asciiWriter/marks.py new file mode 100644 index 0000000..7610339 --- /dev/null +++ b/asciiWriter/marks.py @@ -0,0 +1,24 @@ +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) diff --git a/asciiWriter/patterns.py b/asciiWriter/patterns.py new file mode 100644 index 0000000..2c7a817 --- /dev/null +++ b/asciiWriter/patterns.py @@ -0,0 +1,67 @@ +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 diff --git a/asciiWriter/utils.py b/asciiWriter/utils.py new file mode 100644 index 0000000..352db33 --- /dev/null +++ b/asciiWriter/utils.py @@ -0,0 +1,52 @@ +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 diff --git a/image.py b/image.py new file mode 100644 index 0000000..5faa389 --- /dev/null +++ b/image.py @@ -0,0 +1,30 @@ +#!/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 could 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 diff --git a/image_random_char.py b/image_random_char.py new file mode 100644 index 0000000..cdb037c --- /dev/null +++ b/image_random_char.py @@ -0,0 +1,26 @@ +#!/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 diff --git a/image_rotate.py b/image_rotate.py new file mode 100644 index 0000000..bdedc52 --- /dev/null +++ b/image_rotate.py @@ -0,0 +1,32 @@ +#!/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 diff --git a/image_sentence.py b/image_sentence.py new file mode 100644 index 0000000..b8245fd --- /dev/null +++ b/image_sentence.py @@ -0,0 +1,31 @@ +#!/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 diff --git a/images/blobs-small.png b/images/blobs-small.png new file mode 100644 index 0000000..dfeae83 Binary files /dev/null and b/images/blobs-small.png differ diff --git a/images/blobs.png b/images/blobs.png new file mode 100644 index 0000000..24820be Binary files /dev/null and b/images/blobs.png differ diff --git a/images/shapes.png b/images/shapes.png new file mode 100644 index 0000000..abb7a78 Binary files /dev/null and b/images/shapes.png differ diff --git a/line.py b/line.py new file mode 100644 index 0000000..2d7669e --- /dev/null +++ b/line.py @@ -0,0 +1,28 @@ +#!/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 diff --git a/line_random_char.py b/line_random_char.py new file mode 100644 index 0000000..74d1679 --- /dev/null +++ b/line_random_char.py @@ -0,0 +1,30 @@ +#!/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 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..202bcfc --- /dev/null +++ b/readme.md @@ -0,0 +1,61 @@ +# ASCII-ART-BUT-WITH-UNICODE + +
+---------H---------H---------H---------H---------H---------H---------H---------H---------H---------H
+-------------------e------e-------e------e-------e-------e------e-------e------e-------e------------
+----------------------------l----l-----l----l----l----l----l-----l----l----l------------------------
+------------------------------------l---l--l--l--l--l--l--l---l--l----------------------------------
+-------------------------------------------oo-oo-o-oo-oo-o------------------------------------------
+-----------------------------------------------     ------------------------------------------------
+-------------------------------------------------W--------------------------------------------------
+------------------------------------------------ooo-------------------------------------------------
+---------------------------------------------rrrrrrrrrr---------------------------------------------
+----------------------------------------l-l-l--l-l-l--l-l-l-l---------------------------------------
+---------------------------------d---d---d---d---d---d---d---d---d----d-----------------------------
+------------------------!-----!-----!------!-----!-----!------!-----!-----!------!------------------
+-------------- -------- -------- ------- -------- -------- ------- -------- -------- -------- ------
+----H----------H----------H-----------H----------H----------H-----------H----------H----------H-----
+--------e-------------e------------e-------------e-------------e------------e-------------e---------
+-l---------------l---------------l---------------l---------------l---------------l---------------l--
+--------------l----------------l-----------------l-----------------l----------------l---------------
+-----------o------------------o------------------o------------------o------------------o------------
+--------- ------------------- ------------------- ------------------- ------------------- ----------
+---------W-------------------W-------------------W-------------------W-------------------W----------
+----------o------------------o-------------------o-------------------o------------------o-----------
+------------r------------------r-----------------r-----------------r------------------r-------------
+---------------l----------------l----------------l----------------l----------------l----------------
+-----l-------------d--------------d--------------d--------------d--------------d-------------l------
+------------o-----------!------------!-----------!-----------!------------!-----------o------------e
+---------e--------- --------- --------- --------- --------- --------- --------- ---------l---------H
+-------------------l------W-------H------H-------H-------H------H-------W------l-------e------------
+----------------------------l----o-----e----e----e----e----e-----o----o----l------------------------
+------------------------------------o---r--l--l--l--l--l--r--- --l----------------------------------
+------------------------------------------- l-ll-l-ll-lW-o------------------------------------------
+-----------------------------------------------Wdooo------------------------------------------------
+-------------------------------------------------o--------------------------------------------------
+------------------------------------------------rW -------------------------------------------------
+---------------------------------------------lHoooooHdr---------------------------------------------
+----------------------------------------d-e-r--r-r-r--r-e-!-l---------------------------------------
+---------------------------------!---l---l---l---l---l---l---l--- ----d-----------------------------
+------------------------ -----l-----d------d-----d-----d------d-----l-----H------!------------------
+--------------H--------o--------!-------!--------!--------!-------!--------o--------e-------- ------
+----e---------- ---------- ----------- ---------- ---------- ----------- ---------- ----------l-----
+--------W-------------H------------H-------------H-------------H------------H-------------W---------
+-o---------------e---------------e---------------e---------------e---------------e---------------o--
+--------------l----------------l-----------------l-----------------l----------------l---------------
+-----------l------------------l------------------l------------------l------------------l------------
+---------o-------------------o-------------------o-------------------o-------------------o----------
+--------- ------------------- ------------------- ------------------- ------------------- ----------
+----------W------------------W-------------------W-------------------W------------------W-----------
+------------o------------------o-----------------o-----------------o------------------o-------------
+---------------r----------------r----------------r----------------r----------------r----------------
+-----r-------------l--------------l--------------l--------------l--------------l-------------r------
+------------l-----------d------------d-----------d-----------d------------d-----------l------------l
+
+ +Work in progress :) + +# Requirements + +* pillow + diff --git a/repeated_line.py b/repeated_line.py new file mode 100644 index 0000000..acee358 --- /dev/null +++ b/repeated_line.py @@ -0,0 +1,39 @@ +#!/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 diff --git a/repeated_sinus.py b/repeated_sinus.py new file mode 100644 index 0000000..0efbf73 --- /dev/null +++ b/repeated_sinus.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 + +from asciiWriter.patterns import sinus_vertical +from asciiWriter.utils import make_lines, visit, print_lines, merge +from asciiWriter.marks import sentence, space + +# Define width and height of the output +width = 75 +height = 75 + +# As we draw multiple sinoids we will collect +# them in a list of layers +layers = [] + +# Loop through an offset from -40 to 40 in steps of 10 +for x in range(-40, 40, 10): + # Set the pattern with the changing offset + pattern = sinus_vertical(period=40, amplitude=30, offset=x) + # We use a sentence to draw the text + mark = sentence('OPEN DESIGN COURSE ') + # Define a blank character + blank = space() + + # Make the canvas + lines = make_lines(width, height) + + # Draw the sinoid, but add it to the list + result = visit(lines, pattern, mark, blank) + # Add it the result to the list of layers + layers.append(result) + +# Merge the layers into one layer again +merged = merge(width, height, blank(), layers) + +# Print the result +print_lines(merged) diff --git a/repeated_sinus_amplitude_variation.py b/repeated_sinus_amplitude_variation.py new file mode 100644 index 0000000..4acb8a2 --- /dev/null +++ b/repeated_sinus_amplitude_variation.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +from asciiWriter.patterns import sinus_vertical +from asciiWriter.utils import make_lines, visit, print_lines, merge +from asciiWriter.marks import sentence, space + +import random + +# Define width and height of the output +width = 75 +height = 75 + +# As we draw multiple sinoids we will collect +# them in a list of layers +layers = [] + +# Loop through an amplitude of -50 to 50 in steps of 10 +for amplitude in range(-50, 50, 10): + # Set the pattern with the changing amplitude + pattern = sinus_vertical(period=40, amplitude=amplitude) + # We use a sentence to draw the text + mark = sentence('OPEN DESIGN COURSE ') + # Define a blank character + blank = space() + + # Make the canvas + lines = make_lines(width, height) + # Draw the sinoid, but add it to the list + result = visit(lines, pattern, mark, blank) + # Add it the result to the list of layers + layers.append(result) + +# Merge the layers into one layer again +merged = merge(width, height, blank(), layers) + +# Print the result +print_lines(merged) diff --git a/sinus.py b/sinus.py new file mode 100644 index 0000000..8d21ffc --- /dev/null +++ b/sinus.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +from asciiWriter.patterns import sinus_vertical +from asciiWriter.utils import make_lines, visit, print_lines +from asciiWriter.marks import sentence, space, single + +# Define width and height of the output +width = 75 +height = 75 + +# Set the pattern we use to draw, in this case a +# sinoid, with period of 40 lines, and an amplitude +# of 30 characters. Slightly less than half our canvas width +pattern = sinus_vertical(period=40, amplitude=30) +# We use a sentence to draw the text +mark = sentence('OPEN DESIGN COURSE ') +# Define a blank character +blank = single(' ') + +# Make the canvas +lines = make_lines(width, height) + +# Draw the sinoid +result = visit(lines, pattern, mark, blank) + +# Output the result +print_lines(result) \ No newline at end of file diff --git a/test.py b/test.py new file mode 100644 index 0000000..178f110 --- /dev/null +++ b/test.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +from asciiWriter.patterns import sinus_vertical, cross +from asciiWriter.utils import make_lines, visit, print_lines, merge +from asciiWriter.marks import sentence, space, single + +# Define width and height of the output +width = 100 +height = 50 + +# As we draw multiple sinoids we will collect +# them in a list of layers +layers = [] + +# Loop through an offset from -40 to 40 in steps of 10 +for x in range(-50, 50, 10): + + # Set the pattern with the changing offset + pattern = cross() + # We use a sentence to draw the text + mark = sentence('Hello World! ') + # Define a blank character + blank = single('-') + + # Make the canvas + lines = make_lines(width, height) + + # Draw the sinoid, but add it to the list + result = visit(lines, pattern, mark, blank) + # Add it the result to the list of layers + layers.append(result) + +# Merge the layers into one layer again +merged = merge(width, height, blank(), layers) + +# Print the result +print_lines(merged)