Browse Source

first commit :)

master
manetta 5 years ago
commit
1b6648c858
  1. 2
      asciiWriter/__init__.py
  2. BIN
      asciiWriter/__pycache__/__init__.cpython-36.pyc
  3. BIN
      asciiWriter/__pycache__/__init__.cpython-37.pyc
  4. BIN
      asciiWriter/__pycache__/marks.cpython-36.pyc
  5. BIN
      asciiWriter/__pycache__/marks.cpython-37.pyc
  6. BIN
      asciiWriter/__pycache__/patterns.cpython-36.pyc
  7. BIN
      asciiWriter/__pycache__/patterns.cpython-37.pyc
  8. BIN
      asciiWriter/__pycache__/utils.cpython-36.pyc
  9. BIN
      asciiWriter/__pycache__/utils.cpython-37.pyc
  10. 5
      asciiWriter/asciiWriter.py
  11. 49
      asciiWriter/draw.py
  12. 24
      asciiWriter/marks.py
  13. 67
      asciiWriter/patterns.py
  14. 52
      asciiWriter/utils.py
  15. 30
      image.py
  16. 26
      image_random_char.py
  17. 32
      image_rotate.py
  18. 31
      image_sentence.py
  19. BIN
      images/blobs-small.png
  20. BIN
      images/blobs.png
  21. BIN
      images/shapes.png
  22. 28
      line.py
  23. 30
      line_random_char.py
  24. 61
      readme.md
  25. 39
      repeated_line.py
  26. 36
      repeated_sinus.py
  27. 37
      repeated_sinus_amplitude_variation.py
  28. 27
      sinus.py
  29. 37
      test.py

2
asciiWriter/__init__.py

@ -0,0 +1,2 @@
#!/usr/bin/env python3

BIN
asciiWriter/__pycache__/__init__.cpython-36.pyc

Binary file not shown.

BIN
asciiWriter/__pycache__/__init__.cpython-37.pyc

Binary file not shown.

BIN
asciiWriter/__pycache__/marks.cpython-36.pyc

Binary file not shown.

BIN
asciiWriter/__pycache__/marks.cpython-37.pyc

Binary file not shown.

BIN
asciiWriter/__pycache__/patterns.cpython-36.pyc

Binary file not shown.

BIN
asciiWriter/__pycache__/patterns.cpython-37.pyc

Binary file not shown.

BIN
asciiWriter/__pycache__/utils.cpython-36.pyc

Binary file not shown.

BIN
asciiWriter/__pycache__/utils.cpython-37.pyc

Binary file not shown.

5
asciiWriter/asciiWriter.py

@ -0,0 +1,5 @@
#!/usr/bin/env python3
import utils
import patterns
import marks

49
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)]))

24
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)

67
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

52
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)))

30
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)

26
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)

32
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)

31
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)

BIN
images/blobs-small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
images/blobs.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

BIN
images/shapes.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

28
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)

30
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)

61
readme.md

@ -0,0 +1,61 @@
# ASCII-ART-BUT-WITH-UNICODE
<pre>
---------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
</pre>
Work in progress :)
# Requirements
* pillow

39
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)

36
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)

37
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)

27
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)

37
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)
Loading…
Cancel
Save