-
Notifications
You must be signed in to change notification settings - Fork 38
/
colordots.py
executable file
·75 lines (60 loc) · 1.78 KB
/
colordots.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import turtle
import random
import sys
from datetime import datetime
if len(sys.argv) < 3:
print("Please call this program as follows:")
print(" colordots.py lolim hilim")
print("where lolim and hilim are integers and lolim <= hilim")
exit()
try:
dotsLower = int(sys.argv[1])
except ValueError:
print("The value for the LOWER limit of the number of dots must be an integer")
exit()
try:
dotsUpper = int(sys.argv[2])
except ValueError:
print("The value for the UPPER limit of the number of dots must be an integer")
exit()
if dotsUpper >= dotsLower:
numDots = random.randint(dotsLower, dotsUpper)
print(str(numDots) + " dots will be plotted")
else:
print("The value for the upper limit of dots must be larger than the value for the lower limit.")
exit()
t = turtle.Turtle()
s = turtle.Screen()
s.bgcolor(0, 0, 0)
t.pencolor("white")
t.hideturtle()
c = turtle.Turtle()
c.pencolor("white")
c.hideturtle()
limitX, limitY = t.screen.screensize()
t.penup()
c.penup()
c.goto(limitX, limitY)
print("\nProcess START: " + str(datetime.now()))
for i in range(numDots):
tx, ty = t.position()
t.forward(1)
t.penup()
angle = random.randint(1, 359)
t.right(angle)
skip = random.randint(1, 100)
t.forward(skip)
if tx < (-1 * limitX) or tx > limitX or ty < (-1 * limitY) or ty > limitY:
x = random.randint(-1 * limitX, limitX)
y = random.randint(-1 * limitY, limitY)
t.goto(x, y)
c.clear()
c.write(str(i+1) + " of " + str(numDots))
j = random.randint(0, 99)
t.pencolor(random.random(), random.random(), random.random())
t.pendown()
if t.isvisible():
t.hideturtle()
print("Process END: " + str(datetime.now()))
print("Please close graphics window to end program.")
turtle.mainloop()