Skip to content

Commit ac6b053

Browse files
committed
adding quiet art
Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>
1 parent 8e4ac1a commit ac6b053

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

codeart/client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ def get_parser():
2929
action="store_true",
3030
)
3131

32+
parser.add_argument(
33+
"--quiet",
34+
dest="quiet",
35+
help="suppress extra verbosity",
36+
default=False,
37+
action="store_true",
38+
)
39+
3240
description = "actions for Code Art generator"
3341
subparsers = parser.add_subparsers(
3442
help="codeart actions", title="actions", description=description, dest="command"
@@ -115,7 +123,9 @@ def main():
115123
color_lookup = generate_color_lookup(images)
116124

117125
# Generate an image with text (dinosaur!)
118-
generate_codeart_text(text, color_lookup, outfile="index.html")
126+
generate_codeart_text(
127+
text, color_lookup, outfile="index.html", quiet=args.quiet
128+
)
119129

120130
else:
121131
parser.print_help()

codeart/graphics.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727

2828

2929
def generate_codeart(
30-
template, color_lookup, top=20, sample=15, bgcolor="white", outfile="codeart.html"
30+
template,
31+
color_lookup,
32+
top=20,
33+
sample=15,
34+
bgcolor="white",
35+
outfile="codeart.html",
36+
quiet=False,
3137
):
3238
"""generate codeart will take a template image and generate a web interface
3339
for the same image (plotted with the images from the color lookup)
@@ -43,7 +49,9 @@ def generate_codeart(
4349
for x in range(width):
4450
for y in range(height):
4551

46-
print("x: %s y: %s" % (x, y), end="\r")
52+
if not quiet:
53+
print("x: %s y: %s" % (x, y), end="\r")
54+
4755
# And take only every [sample]th pixel
4856
if x % sample == 0 and y % sample == 0:
4957
cpixel = pixels[x, y]
@@ -82,6 +90,7 @@ def generate_codeart_text(
8290
width=600,
8391
height=600,
8492
coords=None,
93+
quiet=False,
8594
):
8695
image = Image.new("RGBA", (width, height))
8796
draw = ImageDraw.Draw(image)
@@ -101,7 +110,8 @@ def generate_codeart_text(
101110

102111
for x in range(width):
103112
for y in range(height):
104-
print("x: %s y: %s" % (x, y), end="\r")
113+
if not quiet:
114+
print("x: %s y: %s" % (x, y), end="\r")
105115
cpixel = pixels[x, y]
106116
if sum(cpixel) != 0:
107117
# We don't take the exact match, but rather some distance from the top
@@ -132,6 +142,7 @@ def generate_colored_image(
132142
bcol="B",
133143
maxwidth=600,
134144
maxheight=600,
145+
quiet=False,
135146
):
136147
"""This function will take an input image and color vectors,
137148
and generates a version of the image mapped to the color space of
@@ -160,7 +171,8 @@ def generate_colored_image(
160171
for x in range(width):
161172
for y in range(height):
162173

163-
print("%s %s" % (x, y), end="\r")
174+
if not quiet:
175+
print("%s %s" % (x, y), end="\r")
164176
rgb_pixel = pixels[x, y]
165177

166178
# Create a temporary copy to calculate the closest

codeart/nlp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def text2sentences(text, remove_non_english_chars=True):
2929
try:
3030
tokenizer = nltk.data.load("tokenizers/punkt/english.pickle")
3131
except:
32-
nltk.download('punkt')
32+
nltk.download("punkt")
3333
tokenizer = nltk.data.load("tokenizers/punkt/english.pickle")
3434

3535
if remove_non_english_chars:

0 commit comments

Comments
 (0)