Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from tkinter import *
- root = Tk()
- root.title("Second Exercise")
- root.geometry("1500x400")
- root.resizable(False, False)
- canvas = Canvas(root, bg="green")
- canvas.pack(fill=BOTH, expand=True)
- canvas.create_rectangle(0, 40, 1500, 360, fill='black')
- speed = 0.005
- # Габариты - power = 10
- # Ближний - power = 500
- # Дальний - power = 1000
- power = 10
- def roundRect(type: str, x, y, x2=None, y2=None, sharpness=5, **kwargs):
- if sharpness < 2:
- sharpness = 2
- if type == "rect":
- x = [x, x2, x2, x]
- y = [y, y, y2, y2]
- ratioMultiplier = sharpness - 1
- ratioDividend = sharpness
- points = []
- for i in range(len(x)):
- # Set vertex
- points.append(x[i])
- points.append(y[i])
- if i != (len(x) - 1):
- points.append((ratioMultiplier * x[i] + x[i + 1]) / ratioDividend)
- points.append((ratioMultiplier * y[i] + y[i + 1]) / ratioDividend)
- points.append((ratioMultiplier * x[i + 1] + x[i]) / ratioDividend)
- points.append((ratioMultiplier * y[i + 1] + y[i]) / ratioDividend)
- else:
- points.append((ratioMultiplier * x[i] + x[0]) / ratioDividend)
- points.append((ratioMultiplier * y[i] + y[0]) / ratioDividend)
- points.append((ratioMultiplier * x[0] + x[i]) / ratioDividend)
- points.append((ratioMultiplier * y[0] + y[i]) / ratioDividend)
- points.append(x[0])
- points.append(y[0])
- return canvas.create_polygon(points, **kwargs, smooth=TRUE)
- car = roundRect('rect', 40, 60, 210, 170, 5, fill='blue')
- light_1 = roundRect('poly', [230, 230 + power, 230 + power], [85, 60, 110], sharpness=4, fill='yellow')
- light_2 = roundRect('poly', [230, 230 + power, 230 + power], [145, 120, 170], sharpness=4, fill='yellow')
- while True:
- for x in range(0, 1500, 50):
- canvas.create_rectangle(x, 190, x + 20, 200, fill='white')
- canvas.move(car, 0, -4)
- canvas.move(light_1, 0, -4)
- canvas.move(light_2, 0, -4)
- canvas.update()
- time.sleep(speed)
- for x in range(0, 1500, 50):
- canvas.create_rectangle(x, 190, x + 20, 200, fill='black')
- for x in range(25, 1500, 50):
- canvas.create_rectangle(x, 190, x + 20, 200, fill='white')
- canvas.move(car, 0, 4)
- canvas.move(light_1, 0, 4)
- canvas.move(light_2, 0, 4)
- canvas.update()
- time.sleep(speed)
- for x in range(25, 1500, 50):
- canvas.create_rectangle(x, 190, x + 20, 200, fill='black')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement