Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_alias_line_draw.py
- import tkinter as tk
- def draw_line(point_a, point_b):
- num_squares = max(abs(point_b[0] - point_a[0]), abs(point_b[1] - point_a[1]))
- square_size = 5
- # Draw the line using squares
- for i in range(0, num_squares + 1, square_size):
- x = point_a[0] + i * (point_b[0] - point_a[0]) / num_squares
- y = point_a[1] + i * (point_b[1] - point_a[1]) / num_squares
- canvas.create_rectangle(x, y, x + square_size - 1, y + square_size - 1, outline="", fill="black")
- # Example of usage
- root = tk.Tk()
- canvas = tk.Canvas(root, width=300, height=300)
- canvas.pack()
- point_a = (100, 50)
- point_b = (250, 200)
- draw_line(point_a, point_b)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement