Skip to content

Instantly share code, notes, and snippets.

@benkiel
Created August 12, 2016 15:05
Show Gist options
  • Save benkiel/8496963c7fd5594a085bf51503faf40f to your computer and use it in GitHub Desktop.
Save benkiel/8496963c7fd5594a085bf51503faf40f to your computer and use it in GitHub Desktop.
Make Pattern from Text
from __future__ import division
morseAlphabet ={
"A" : [1,2,],
"B" : [2,1,1,1,],
"C" : [2,1,2,1,],
"D" : [2,1,1,],
"E" : [1,],
"F" : [1,1,2,1,],
"G" : [2,2,1,],
"H" : [1,1,1,1,],
"I" : [1,1,],
"J" : [1,2,2,2,],
"K" : [2,1,2,],
"L" : [1,2,1,1,],
"M" : [2,2,],
"N" : [2,1,],
"O" : [2,2,2,],
"P" : [1,2,2,1,],
"Q" : [2,2,1,2,],
"R" : [1,2,1,],
"S" : [1,1,1,],
"T" : [2,],
"U" : [1,1,2,],
"V" : [1,1,1,2,],
"W" : [1,2,2,],
"X" : [2,1,1,2,],
"Y" : [2,1,2,2,],
"Z" : [2,2,1,1,],
" " : [0]
}
def rotate(string,n):
n = n % len(string)
return string[n:] + string[:n]
def draw(text, orgin, height, width, gap):
total = 0
number = 0
for letter in text.upper():
for x in morseAlphabet[letter]:
total += x
if x is not 0:
number += 1
unit = (width - gap*number) / total
for letter in text.upper():
for x in morseAlphabet[letter]:
line(orgin, (orgin[0] + x * unit, orgin[1]))
orgin = (orgin[0] + x * unit + gap, orgin[1])
stroke(0)
strokeWidth(1)
offset = 10
text = "Fuck Donald Trump"
counter = 0
for y in range(0, height(), offset):
t = rotate(text, counter)
draw(t, (0,y), 0, width(), 5)
counter += 1
print rotate(text, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment