Skip to content

Commit a731b5f

Browse files
authored
Add files via upload
1 parent 1281e6e commit a731b5f

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

snowtext/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# snowtext
2+
3+
A python 3 module that prints scattered asterisks in place of spaces of a text that is divided into equal lines of custom length.
4+
Text symbol or string can be set, default is asterisk (`*`).

snowtext/run.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Author: Daniela Grothe
2+
# GitHub: https://github.com/DGrothe-PhD
3+
4+
from snowtext import Scatter
5+
6+
textsample = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
7+
8+
blindtext = Scatter(textsample)
9+
blindtext.TextCarpet(50)
10+
blindtext.scatter()

snowtext/snowtext.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Author: Daniela Grothe
2+
# GitHub: https://github.com/DGrothe-PhD
3+
4+
# Replace blanks in a text with an asterisk, replace words of the text with blanks
5+
# to create a (pseudo-)random snow pattern
6+
7+
class Scatter:
8+
__piece = ["*"]
9+
__textsample = ""
10+
__lineslist = []
11+
def __init__(self, tx):
12+
self.__textsample = tx
13+
def SetTextSample(self, tx):
14+
self.__textsample = tx
15+
16+
#choose your own symbol or string to be scattered
17+
def SetPrintableObject(self, p):
18+
self.__piece.append(p)
19+
def ClearPrintableObjects(self):
20+
self.__piece = []
21+
22+
# Split (roughly all of) the text in portions (lines) of linelength (integer) characters
23+
# note: TextCarpet ignores the last len(text) modulo linelength characters.
24+
# For splitting readable text, use SplitToShort instead.
25+
def TextCarpet(self, linelength):
26+
self.__lineslist = []
27+
for i in range(0,len(self.__textsample)//linelength):
28+
self.__lineslist.append(self.__textsample[i*linelength:(i+1)*linelength])
29+
30+
def SplitToShort(self, tx, linelength):
31+
self.__lineslist = []
32+
for i in range(0,len(__textsample)//linelength):
33+
self.__lineslist.append(self.__textsample[i*linelength:(i+1)*linelength])
34+
self.__lineslist.append(self.__textsample[(i+1)*linelength+1:len(tx)])
35+
return self.__lineslist
36+
#
37+
def scatter(self):
38+
foo = []
39+
i=0
40+
if len(self.__lineslist)<2:
41+
pass#return "Too low number of lines or text too short."
42+
for x in self.__lineslist:
43+
if i<100: # don't generate too large output
44+
buf= x.split()
45+
a = ""
46+
k = len(self.__piece)
47+
for j in range(0,len(buf)):
48+
a+= (" "*len(buf[j]))
49+
a+=self.__piece[j%k]
50+
foo.append(a)
51+
i+=1
52+
print("\n".join(foo))

0 commit comments

Comments
 (0)