Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import messagebox
- import random
- import math
- import clr
- import numpy as np
- import os
- root = Tk()
- root.geometry('800x600')
- c = Canvas(root, width=800, height=600, bg='white')
- c.pack()
- x0 = int()
- y0 = int()
- x1 = int()
- y1 = int()
- x0_label = Label(text="x0: ")
- y0_label = Label(text="y0: ")
- x1_label = Label(text="x1: ")
- y1_label = Label(text="y1: ")
- max_rand = 0
- line_array = [[random.randint(200, 500), random.randint(200, 500)], [random.randint(400, 600), random.randint(200, 600)]]
- def draw_line(self, x1=0, y1=0, x2=0, y2=0):
- dx = x2 - x1
- dy = y2 - y1
- sign_x = 1 if dx > 0 else -1 if dx < 0 else 0
- sign_y = 1 if dy > 0 else -1 if dy < 0 else 0
- if dx < 0: dx = -dx
- if dy < 0: dy = -dy
- if dx > dy:
- pdx, pdy = sign_x, 0
- es, el = dy, dx
- else:
- pdx, pdy = 0, sign_y
- es, el = dx, dy
- x, y = x1, y1
- error, t = el / 2, 0
- c.create_line(x, y, x + 1, y)
- while t < el:
- error -= es
- if error < 0:
- error += el
- x += sign_x
- y += sign_y
- else:
- x += pdx
- y += pdy
- t += 1
- c.create_line(x, y, x + 1, y)
- def check_x():
- if line_array[0][0] < line_array[1][0]:
- global max_rand
- max_rand = line_array[0][0]
- else:
- max_rand = line_array[1][0]
- return
- def slope():
- dy = float(line_array[1][1] - line_array[0][1])
- dx = float(line_array[1][0] - line_array[0][0])
- k = float(math.atan(dy / dx))
- return k
- def change_line_coord():
- line_array[0][0] = input()
- line_array[0][1] = input()
- line_array[1][0] = input()
- line_array[1][1] = input()
- def start():
- os.system('CLS')
- draw_line(c, line_array[0][0], line_array[0][1], line_array[1][0], line_array[1][1])
- check_x()
- triangle_array = [[random.randint(100, max_rand), random.randint(150, 500)],
- [random.randint(150, max_rand), random.randint(150, 500)],
- [random.randint(150, max_rand), random.randint(150, 500)]]
- draw_line(c, triangle_array[0][0], triangle_array[0][1], triangle_array[1][0], triangle_array[1][1])
- draw_line(c, triangle_array[1][0], triangle_array[1][1], triangle_array[2][0], triangle_array[2][1])
- draw_line(c, triangle_array[2][0], triangle_array[2][1], triangle_array[0][0], triangle_array[0][1])
- result1 = np.matmul([[triangle_array[0][0], triangle_array[0][1], 1],
- [triangle_array[1][0], triangle_array[1][1], 1],
- [triangle_array[2][0], triangle_array[2][1], 1]],
- [[1, 0, 0], [0, 1, 0], [-line_array[0][0], -line_array[0][1], 1]])
- result2 = np.matmul(result1, [[math.cos(-slope()), (math.sin(-slope())), 0],
- [-math.sin(-slope()), (math.cos(-slope())), 0], [0, 0, 1]])
- result3 = np.matmul(result2, [[1, 0, 0], [0, -1, 0], [0, 0, 1]])
- result4 = np.matmul(result3, [[math.cos(slope()), (math.sin(slope())), 0],
- [-math.sin(slope()), (math.cos(slope())), 0], [0, 0, 1]])
- result5 = np.matmul(result4, [[1, 0, 0], [0, 1, 0], [line_array[0][0], line_array[0][1], 1]])
- draw_line(c, result5[0][0], result5[0][1], result5[1][0], result5[1][1])
- draw_line(c, result5[1][0], result5[1][1], result5[2][0], result5[2][1])
- draw_line(c, result5[2][0], result5[2][1], result5[0][0], result5[0][1])
- return
- try:
- start()
- btn = Button(root,command = change_line_coord, text="Hello")
- btn.pack()
- except:
- pass
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement