Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- l = [[" "]]
- l_len_y = len(l)
- l_len_x = len(l[0])
- class point:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def out():
- for i in l:
- print("".join(i))
- def plot(p, c):
- x = p.x; y = p.y
- global l_len_y
- if y > l_len_y:
- for i in range(l_len_y, y):
- l.append([" " for n in range(l_len_x)])
- l_len_y = y
- global l_len_x
- if x > l_len_x:
- for i in range(l_len_y):
- l[i].extend([" " for n in range(x-l_len_x)])
- l_len_x = x
- l[y-1][x-1] = c
- def draw_line(p0, p1, c):
- x0 = p0.x; y0 = p0.y
- x1 = p1.x; y1 = p1.y
- del p0, p1
- if x0 < 0 or x1 < 0 or y0 < 0 or y1 < 0:
- print("negative coordinate")
- return
- if x1 == x0:
- for y in range(y0, y1):
- plot(point(x0, y), c)
- return
- s = (y1-y0)/(x1-x0)
- if s < -1 or s > 1:
- if y0 > y1:
- x0, x1 = x1, x0
- y0, y1 = y1, y0
- s = 1/s
- for y in range(y0, y1+1):
- x = x0+round(s*(y-y0))
- plot(point(x, y), c)
- else:
- if x0 > x1:
- x0, x1 = x1, x0
- y0, y1 = y1, y0
- for x in range(x0, x1+1):
- y = y0+round(s*(x-x0))
- plot(point(x, y), c)
- a = "."
- p = "*"
- p0 = point(3, 1); p1 = point(22, 10); p2 = point(41, 1)
- p3 = point(1, 15); p4 = point(43, 15); p5 = point(22, 15)
- draw_line(p0, p1, a)
- draw_line(p1, p2, a)
- draw_line(p0, p3, a)
- draw_line(p2, p4, a)
- draw_line(p3, p4, a)
- draw_line(p1, p5, a)
- plot(p0, p)
- plot(p1, p)
- plot(p2, p)
- plot(p3, p)
- plot(p4, p)
- plot(p5, p)
- out()
- import os
- if 'win' in os.sys.platform:
- os.system("PAUSE")
Advertisement
Add Comment
Please, Sign In to add comment