-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomPoints.py
More file actions
89 lines (73 loc) · 1.88 KB
/
RandomPoints.py
File metadata and controls
89 lines (73 loc) · 1.88 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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import turtle
import random as r
import time
import math
don = turtle.Turtle()
screen = turtle.Screen()
don.hideturtle()
don.speed(0)
don.pencolor('white')
screen.colormode(255)
screen.bgcolor('black')
screen.setup(900,700,200,0)
screen.tracer(0,0)
class Point:
def __init__(self,x,y):
self.x = x
self.y = y
def draw(self,drawer):
drawer.pensize(3)
drawer.penup()
drawer.setpos(self.x-1,self.y-1)
drawer.pendown()
for i in range(0,4):
drawer.forward(3)
drawer.left(90)
class Line:
def __init__(self,P1,P2):
self.P1 = P1
self.P2 = P2
def draw(self,drawer):
drawer.pensize(1)
drawer.penup()
drawer.setpos(self.P1.x,self.P1.y)
drawer.pendown()
drawer.setpos(self.P2.x, self.P2.y)
points = []
lines = []
def lop(number):
x = 400
y = 200
for i in range(0,number):
points.append(Point(r.randint(-x,x),r.randint(-y,y)))
go = True
print('Printing...')
drawAll(points, don)
counter = 0
for p1 in points:
counter+=1
for p2 in points:
go = True
tempLine = Line(p1,p2)
for ch in lines:
if (ch.P1 == p1 and ch.P2 == p2) or (ch.P1 == p2 and ch.P2 == p1):
go = False
if go:
lines.append(tempLine)
print('Point ', counter, ' Finished')
drawAll(lines, don)
lines.clear()
print('Done')
time.sleep(2)
don.clear()
lines.clear()
points.clear()
lop(number+1)
def drawAll(_points,drawer):
for p in _points:
drawer.pencolor(r.randint(150,255),r.randint(150,255),r.randint(150,255))
p.draw(drawer)
screen.update()
time.sleep(0.2)
lop(5)
screen.exitonclick()