# Day 16
# __ _ _ _
# / /(_)_ __ ___ __ _ _ __ /\/\ ___ | |_(_) ___ _ __
# / / | | '_ \ / _ \/ _` | '__| / \ / _ \| __| |/ _ \| '_ \
# / /__| | | | | __/ (_| | | / /\/\ \ (_) | |_| | (_) | | | |
# \____/_|_| |_|\___|\__,_|_| \/ \/\___/ \__|_|\___/|_| |_|
from tkinter import *
import time
# main
root = Tk()
root.title("Moving Objects")
root.resizable(True, True)
root.geometry("800x800+200+200")
# canvas
bg = PhotoImage(file="phodo/Space-Background-Cartoon.png").subsample(5, 5)
c = Canvas(root, width=800, height=800)
c.place(x=10, y=10)
c.create_image(0, 0, image=bg, anchor="nw")
# the cats
# _,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,_
# cat one
cat1img = PhotoImage(file="phodo/Wreck.png").subsample(2, 2)
x1 = 10
y1 = 400
cat1 = c.create_image(x1, y1, image=cat1img)
# cat two
cat2img = PhotoImage(file="phodo/Wave.png").subsample(8, 8)
x2 = 400
y2 = 10
cat2 = c.create_image(x2, y2, image=cat2img)
# cat three
cat3img = PhotoImage(file="phodo/Sepia.png").subsample(5, 5)
x3 = 100
y3 = 50
cat3 = c.create_image(x3, y3, image=cat3img)
# cat four
cat4img = PhotoImage(file="phodo/Abstractionism.png").subsample(4, 4)
x4 = 100
y4 = 50
cat4 = c.create_image(x4, y4, image=cat4img)
# cat five
cat5img = PhotoImage(file="phodo/Anime.png").subsample(7, 7)
x5 = 100
y5 = 50
cat5 = c.create_image(x5, y5, image=cat5img)
# cat Six
cat6img = PhotoImage(file="phodo/Kay-Nielsen.png").subsample(9, 9)
x6 = 40
y6 = 700
cat6 = c.create_image(x6, y6, image=cat6img)
# cat seven
cat7img = PhotoImage(file="phodo/me.png").subsample(3, 3)
x7 = 60
y7 = 200
cat7 = c.create_image(x7, y7, image=cat7img)
# cat eight
cat8img = PhotoImage(file="phodo/claude-monet.png").subsample(9, 9)
x8 = 400
y8 = 400
cat8 = c.create_image(x8, y8, image=cat8img)
# movement
# _,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,__,.-'~'-.,_
moving = True
speed1 = v1 = v2 = speed2 = v3 = v4 = v5 = 1
while moving:
# cat one movement
x1 += 0.5 # move object to right
if x1 > 800: # check for right boundary wrap
x1 = -155
# cat two movement
x2 -= 20
if x2 < -155:
x2 = 800
# cat three movement
y3 -= 3
if y3 < -155:
y3 = 800
# cat four movement
x4 += 5
y4 += 5
if y4 > 800:
y4 = -155
if x4 > 800:
x4 = -155
# cat five movement
x5 += speed1
y5 += 1
speed1 += 0.01
if y5 > 800:
y5 = -155
if x5 > 800:
x5 = -155
# cat six movement
if v1 == 1:
x6 += 5
else:
x6 -= 5
if v2 == 1:
y6 += 5
else:
y6 -= 5
if x6 > 700:
v1 = 0
if x6 < 0:
v1 = 1
if y6 > 700:
v2 = 0
if y6 < 0:
v2 = 1
# cat seven movement
x7 += speed2
if x7 > 800:
x7 = -50
if x7 < -50:
x7 = 800
if v3 == 1:
speed2 += 1
else:
speed2 -= 4
if speed2 == 40:
v3 = 0
if speed2 == -40:
v3 = 1
# cat eight movement
if v4 == 1:
x8 += 4
else:
x8 -= 4
if v5 == 1:
y8 += 7
else:
y8 -= 7
if x8 > 700:
v4 = 0
if x8 < 0:
v4 = 1
if y8 > 700:
v5 = 0
if y8 < 0:
v5 = 1
c.moveto(cat1, x1, y1) # move point to new location
c.moveto(cat2, x2, y2)
c.moveto(cat3, x3, y3)
c.moveto(cat4, x4, y4)
c.moveto(cat5, x5, y5)
c.moveto(cat6, x6, y6)
c.moveto(cat7, x7, y7)
c.moveto(cat8, x8, y8)
time.sleep(0.01) # delay
root.update() # redraw canvas
root.mainloop()