Skip to content

Instantly share code, notes, and snippets.

@ismdeep
Created October 11, 2020 13:04
Show Gist options
  • Save ismdeep/019843ff65863febe8b4de5493b7e87e to your computer and use it in GitHub Desktop.
Save ismdeep/019843ff65863febe8b4de5493b7e87e to your computer and use it in GitHub Desktop.
Python 画动态图
from tkinter import *
from random import randint
width_size = 1920
height_size = 1080
colors = ['red', 'green', 'black', 'yellow', 'blue', 'gray', 'pink', 'purple']
distance = 300
sleep_time = 100
step_count = 1000
canvas = Canvas(width=width_size, height=height_size)
canvas.pack(expand=YES, fill=BOTH)
x0, y0 = randint(1, width_size), randint(1, height_size)
for i in range(step_count):
x1, y1 = randint(max(x0 - distance, 1), min(x0 + distance, width_size)), randint(max(y0 - distance, 1), min(y0 + distance, height_size))
canvas.create_line(x0, y0, x1, y1, width=1, fill=colors[randint(0, len(colors) - 1)])
x0, y0 = x1, y1
canvas.update()
canvas.after(sleep_time)
mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment