AsciiWriter/sinus.py: Difference between revisions

From creative crowd wiki
Jump to navigation Jump to search
(Created page with "==sinus.py== <syntaxhighlight lang="python"> 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 = 70 height = 25 # As we draw multiple sinoids we will collect # them in a list of layers layers = [] # Loop through a range of X, X in steps of X # (the amount of loops is the amount of layers) for x in range(-50, 50,...")
 
No edit summary
Line 1: Line 1:
[[File:Sinus-output.png]]
==sinus.py==
==sinus.py==
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">

Revision as of 11:11, 7 April 2023

Sinus-output.png

sinus.py

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 = 70
height = 25

# As we draw multiple sinoids we will collect
# them in a list of layers
layers = []

# Loop through a range of X, X in steps of X
# (the amount of loops is the amount of layers)
for x in range(-50, 50, 5):
    # Set the pattern with the changing offset
    pattern = sinus_vertical(period=10, amplitude=40, offset=x)
    # We use a sentence to draw the text
    mark = sentence('▚▒▓▞')
    # 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)