-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathRandomText.pv
More file actions
45 lines (37 loc) · 1.21 KB
/
Copy pathRandomText.pv
File metadata and controls
45 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Generate compositions using random text.
"""
size(600, 600)
# A helper-function for choosing what text to draw
def rand_txt():
"""Returns a random string of up to 9 characters."""
t = ""
for i in range(random(10)):
t += chr(random(10,120))
return t
# Define the font family & weight
font("arial", "black")
# Define some colors.
colormode(HSV)
white = color(1,1,1,0.8)
black = color(0,0,0,0.8)
red = color(random(),0,0.2,0.8)
translate(0,-200)
for i in range(100):
# This translation is not reset every time, so it is
# appended to previous translations. This gives us some
# interesting "random walk" positioning effects.
translate(random(-100,100),random(-100,100))
# Save the current transformation. It's a good idea
# to do this in the beginning of a loop. The previous
# transformation state will be restored at the end of the
# indented block of commands.
with transform():
# pick a random font size & color
font(random(800))
fill(choice((white,black,red)))
# Rotate in increments of 45 degrees.
rotate(random(5)*45)
# draw some randomly-selected characters
someText = rand_txt()
text(someText, 0,0)