예제 #1
0
def make_car(canvas: Canvas, top_left: tuple, color='hotpink', tag='car'):
    x = top_left[0]
    y = top_left[1]
    #make car:
    top_id = shapes.make_rectangle(canvas, (x + 50, y - 30),
                                   100,
                                   40,
                                   color=color,
                                   tag=tag)
    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)
예제 #2
0
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)
예제 #3
0
파일: d3.py 프로젝트: eecs110/spring2019
from tkinter import Canvas, Tk
import random
import shapes

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

for i in range(20):
    x = 250
    y = 250 + i * 5
    r = 2 + i * 2
    shapes.make_circle(canvas, (x, y), r, color=None, outline='black', stroke_width=1)

for i in range(20):
    x = 250
    y = 250 - i * 5
    r = 2 + i * 2
    shapes.make_circle(canvas, (x, y), r, color=None, outline='black', stroke_width=1)

for i in range(20):
    x = 250 + i * 5
    y = 250
    r = 2 + i * 2
    shapes.make_circle(canvas, (x, y), r, color=None, outline='black', stroke_width=1)

for i in range(20):
    x = 250 - i * 5
    y = 250
예제 #4
0
from tkinter import Canvas, Tk
import random
import shapes

gui = Tk()
gui.title('Circle')
# initialize canvas:
canvas = Canvas(gui, width=500, height=500, background='#FFFFFF')
canvas.pack()

########################## YOUR CODE BELOW THIS LINE ##############################

shapes.make_circle(canvas, (250, 250),
                   25,
                   color=None,
                   outline='black',
                   stroke_width=2)

########################## YOUR CODE ABOVE THIS LINE ##############################

# makes sure the canvas keeps running:
canvas.mainloop()
예제 #5
0
from tkinter import Canvas, Tk
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()
예제 #6
0
# Challenge:
# Do the same thing as in 05_while_animate, but with
# all 4 shapes:
#   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, 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)
예제 #7
0
from tkinter import Canvas, Tk
import random
import shapes
import math

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

center_x = 250
center_y = 250
distance_from_center = 50
radius_of_individual_circle = 100
num_circles = 30
for i in range(num_circles):
    # calculate new position of x and y
    radians = 360 / num_circles * i * (math.pi / 180)
    dy = distance_from_center * math.sin(radians)
    dx = distance_from_center * math.cos(radians)
    x = center_x + dx
    y = center_y - dy
    shapes.make_circle(canvas, (x, y),
                       radius_of_individual_circle,
                       color=None,
                       outline='black',
                       stroke_width=1)

########################## YOUR CODE ABOVE THIS LINE ##############################
canvas.mainloop()
예제 #8
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()
예제 #9
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()
예제 #10
0
gui.title('Animation')
canvas = Canvas(gui, width=500, height=500, background='white')
canvas.pack()
########################## 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
예제 #11
0
canvas.pack()
########################## 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)

length = 40

# make circle
circle_id = shapes.make_circle(canvas, (60, 60), 50, color='hotpink')

# only animate square rotation thingy 3 times...

counter = 0
num_squares_drawn = 0

counter = 0
while True:
    x1 = round(math.sin(counter), 2)
    x2 = round(math.sin(counter / 20), 2)
    x3 = round(math.sin(counter) * 10, 2)
    x4 = round(math.sin(counter / 20) * 10, 2)
    print(x1, x2, x3, x4)
    shapes.move(canvas, circle_id, x=x2, y=0)
    gui.update()
예제 #12
0
palette = ('#808d8e', '#766c7f', '#947eb0', '#a3a5c3', '#a9d2d5')


# BUILDING A DATASET (A DATASET OF BUBBLES)
# 50 ROWS OF BUBBLES WHERE THE FIRST CELL IS THE NAME OF
# THE BUBBLE AND THE SECOND CELL IS THE SPEED OF THE BUBBLE
bubbles = []
for i in range(0, 50):
    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]