Ejemplo n.º 1
0
    bottom_id = shapes.make_rectangle(canvas, (x, y),
                                      200,
                                      45,
                                      color=color,
                                      tag=tag)
    wheel1_id = shapes.make_circle(canvas, (x + 50, y + 50),
                                   20,
                                   color='black',
                                   tag=tag)
    wheel2_id = shapes.make_circle(canvas, (x + 150, y + 50),
                                   20,
                                   color='black',
                                   tag=tag)


make_car(canvas, (100, 100), tag='car_1')
make_car(canvas, (150, 300), color='teal', tag='car_2')
make_car(canvas, (200, 0), color='blue', tag='car_3')

while True:
    # move car:
    shapes.move(canvas, 'car_1', x=6, y=0)
    shapes.move(canvas, 'car_3', x=0, y=5)

    gui.update()
    time.sleep(.1)

########################## YOUR CODE ABOVE THIS LINE ##############################
# makes sure the canvas keeps running:
canvas.mainloop()
Ejemplo n.º 2
0
gui = Tk()
gui.title('Animation')
canvas = Canvas(gui, width=500, height=500, background='white')
canvas.pack()
########################## YOUR CODE BELOW THIS LINE ##############################

def make_car(canvas:Canvas, top_left:tuple=(0, 0), color:str="#3D9970", tag:str=None):
    x, y = top_left
    shapes.make_rectangle(canvas, (x + 50, y), 100, 40, color=color, tag=tag)
    shapes.make_rectangle(canvas, (x, y + 30), 200, 45, color=color, tag=tag)
    shapes.make_circle(canvas, (x + 50, y + 80), 20, color='black', tag=tag)
    shapes.make_circle(canvas, (x + 150, y + 80), 20, color='black', tag=tag)

make_car(canvas, (100, 100), tag='car_1')
make_car(canvas, (-100, 250), tag='car_2', color='yellow')
make_car(canvas, (500, 400), tag='car_3', color='hotpink')

while True:
    # move car:
    shapes.move(canvas, 'car_1', x=3, y=0)
    shapes.move(canvas, 'car_2', x=10, y=0)
    shapes.move(canvas, 'car_3', x=-4, y=0)
    gui.update()
    time.sleep(.001)



########################## YOUR CODE ABOVE THIS LINE ############################## 
# makes sure the canvas keeps running:
canvas.mainloop()
Ejemplo n.º 3
0
#   6. Make it accelerate (on your own)

#make car:
top_id = shapes.make_rectangle(canvas, (100, 20), 100, 40, tag='car_1')
bottom_id = shapes.make_rectangle(canvas, (50, 50), 200, 45, tag='car_1')
wheel1_id = shapes.make_circle(canvas, (100, 100),
                               20,
                               color='black',
                               tag='car_1')
wheel2_id = shapes.make_circle(canvas, (200, 100),
                               20,
                               color='black',
                               tag='car_1')

# move car:
shapes.move(canvas, 'car_1', x=60, y=0)
gui.update()
time.sleep(1)

# move car again:
shapes.move(canvas, 'car_1', x=60, y=0)
gui.update()
time.sleep(1)

# move car again:
shapes.move(canvas, 'car_1', x=60, y=0)
gui.update()
time.sleep(1)

########################## YOUR CODE ABOVE THIS LINE ##############################
# makes sure the canvas keeps running:
Ejemplo n.º 4
0
import time
import shapes
import math

gui = Tk()
gui.title('Animation')
canvas = Canvas(gui, width=500, height=500, background='white')
canvas.pack()
########################## YOUR CODE BELOW THIS LINE ##############################

shapes.make_circle(canvas, (60, 60), 10, color=None, tag='circle1')
shapes.make_circle(canvas, (200, 30), 20, color=None, tag='circle2')
shapes.make_circle(canvas, (330, 10), 10, color=None, tag='circle3')
shapes.make_circle(canvas, (520, 40), 15, color=None, tag='circle4')

# only animate square rotation thingy 3 times...

counter = 0
num_squares_drawn = 0

counter = 0
while True:
    shapes.move(canvas, 'circle1', x=0, y=3)
    gui.update()
    time.sleep(.001)
    counter += 1

########################## YOUR CODE ABOVE THIS LINE ##############################
# makes sure the canvas keeps running:
canvas.mainloop()
Ejemplo n.º 5
0
from tkinter import Canvas, Tk
import time
import shapes

gui = Tk()
gui.title('Animation')
canvas = Canvas(gui, width=500, height=500, background='white')
canvas.pack()
########################## YOUR CODE BELOW THIS LINE ##############################

# make circle
shapes.make_circle(canvas, (100, 100), 40, color='hotpink', tag='circle_1')
shapes.make_circle(canvas, (100, 100), 20, color='teal', tag='circle_2')

while True:
    shapes.move(canvas, 'circle_1', x=2, y=0)
    shapes.move(canvas, 'circle_2', x=0, y=3)
    gui.update()
    time.sleep(.001)

########################## YOUR CODE ABOVE THIS LINE ##############################
# makes sure the canvas keeps running:
canvas.mainloop()
Ejemplo n.º 6
0
from tkinter import Canvas, Tk
import time
import shapes
import math
import random

gui = Tk()
gui.title('Animation')
canvas = Canvas(gui, width=500, height=500, background='white')
canvas.pack()
########################## YOUR CODE BELOW THIS LINE ##############################

for i in range(0, 100):
    x = random.randint(0, 500)
    y = random.randint(0, 500)
    rad = random.randint(1, 8)
    tag_name = 'circle_' + str(i)
    shapes.make_circle(canvas, (x, y), rad, color=None, tag=tag_name)

while True:
    for i in range(0, 100):
        tag_name = 'circle_' + str(i)
        shapes.move(canvas, tag_name, x=0, y=3)
    gui.update()
    time.sleep(.001)

########################## YOUR CODE ABOVE THIS LINE ##############################
# makes sure the canvas keeps running:
canvas.mainloop()
Ejemplo n.º 7
0
########################## YOUR CODE BELOW THIS LINE ##############################

# Using a while loop, please complete the following:
#   1. Make the circle smoothly move across the screen
#   2. Make it move backwards (on your own)
#   3. Make it move vertically (on your own)
#   4. Make it move diagonally (on your own)
#   5. If it gets to the end, of the screen,
#      make it reverse directions  (on your own)
#   6. Make it oscillate back and forth  (on your own)

# make circle
circle_id = shapes.make_circle(canvas, (100, 100), 40, color='hotpink')

# move circle
shapes.move(canvas, circle_id, x=60, y=0)
gui.update()
time.sleep(1)

# move circle
shapes.move(canvas, circle_id, x=60, y=0)
gui.update()
time.sleep(1)  # pause for 1 second

# move circle
shapes.move(canvas, circle_id, x=60, y=0)
gui.update()
time.sleep(1)  # pause for 1 second

# move circle
shapes.move(canvas, circle_id, x=60, y=0)
Ejemplo n.º 8
0
#   1. Make the car smoothly drive across the screen
#   2. Make it drive backwards (on your own)
#   3. Make it drive vertically (on your own)
#   4. Make it drive diagonally (on your own)
#   5. If it gets to the end, of the screen,
#      make it reverse directions (on your own)
#   6. Make it accelerate (on your own)

#make car:
top_id = shapes.make_rectangle(canvas, (100, 20), 100, 40)
bottom_id = shapes.make_rectangle(canvas, (50, 50), 200, 45)
wheel1_id = shapes.make_circle(canvas, (100, 100), 20, color='black')
wheel2_id = shapes.make_circle(canvas, (200, 100), 20, color='black')

# move car:
shapes.move(canvas, wheel1_id, x=60, y=0)
shapes.move(canvas, wheel2_id, x=60, y=0)
shapes.move(canvas, bottom_id, x=60, y=0)
shapes.move(canvas, top_id, x=60, y=0)
gui.update()
time.sleep(1)

# move car again:
shapes.move(canvas, wheel1_id, x=60, y=0)
shapes.move(canvas, wheel2_id, x=60, y=0)
shapes.move(canvas, bottom_id, x=60, y=0)
shapes.move(canvas, top_id, x=60, y=0)
gui.update()

########################## YOUR CODE ABOVE THIS LINE ##############################
# makes sure the canvas keeps running:
Ejemplo n.º 9
0
    x = random.randint(0, 500) 
    y = random.randint(0, 500)
    rad = random.randint(1, 8)
    tag_name = 'circle_' + str(i)
    shapes.make_circle(
        canvas,
        (x, y),
        rad,
        color=random.choice(palette),
        tag=tag_name
    )

    bubbles.append([tag_name, random.randint(2, 6)])

for bubble in bubbles:
    print(bubble)

while True:
    # each time the screen redraws (gui.update()), each circle
    # moves by 3 units in the y direction.
    for entry in bubbles:
        tag = entry[0]
        speed = entry[1]
        shapes.move(canvas, tag, x=0, y=speed)
    gui.update()
    time.sleep(.01)

########################## YOUR CODE ABOVE THIS LINE ############################## 
# makes sure the canvas keeps running:
canvas.mainloop()