Ejemplo n.º 1
0
def make_creature(canvas, center, size=100, tag='creature', fill='hotpink'):
    radius = size / 2
    # just a demo of how you might think about making your creature:
    left_eye_pos = (center[0] - radius / 4, center[1] - radius / 5)
    right_eye_pos = (center[0] + radius / 4, center[1] - radius / 5)
    eye_width = eye_height = radius / 10

    # IMPORTANT that I'm tagging each of the shapes that makes up my "make_creature"
    # with the tag that the user passed in:
    utilities.make_circle(canvas, center, radius, color=fill, tag=tag)
    utilities.make_oval(canvas,
                        left_eye_pos,
                        eye_width,
                        eye_height,
                        color='black',
                        tag=tag)
    utilities.make_oval(canvas,
                        right_eye_pos,
                        eye_width,
                        eye_height,
                        color='black',
                        tag=tag)
    utilities.make_line(canvas,
                        [(center[0] - radius / 2, center[1] + radius / 3),
                         (center[0], center[1] + radius / 1.2),
                         (center[0] + radius / 2, center[1] + radius / 3)],
                        curvy=True,
                        tag=tag)
Ejemplo n.º 2
0
def make_circle(event):
    global counter
    utilities.make_circle(canvas, (event.x, event.y),
                          20,
                          color='hotpink',
                          tag='circle_' + str(counter))
    counter += 1
Ejemplo n.º 3
0
def make_circle(event):
    tag = 'circle_' + str(len(data))
    utilities.make_circle(canvas, (event.x, event.y),
                          random.uniform(10, 50),
                          color=None,
                          tag=tag)
    data.append({'tag': tag, 'speed': random.uniform(1, 5)})
Ejemplo n.º 4
0
def make_circle(event):
    utilities.make_circle(
        canvas,
        (event.x, event.y),
        20, 
        color='hotpink'
    )
Ejemplo n.º 5
0
def make_circle(x, y):
    global counter
    utilities.make_circle(
        canvas,
        (x, y),
        20, 
        color='hotpink',
        tag='circle_' + str(counter)
    )
    counter += 1
    canvas.focus_set()
Ejemplo n.º 6
0
def make_creature(canvas, center, size=100, tag='creature', fill='hotpink'):
    # just a demo of how you might think about making your creature:
    left_eye_pos = (center[0] - size / 4, center[1] - size / 5)
    right_eye_pos = (center[0] + size / 4, center[1] - size / 5)
    eye_width = eye_height = size / 10
    utilities.make_circle(canvas, center, size, color=fill, tag=tag)
    utilities.make_oval(canvas, left_eye_pos, eye_width, eye_height, color='black', tag=tag)
    utilities.make_oval(canvas, right_eye_pos, eye_width ,eye_height, color='black', tag=tag)
    utilities.make_line(canvas, [
        (center[0] - size / 2, center[1] + size / 3), 
        (center[0], center[1] + size / 1.2), 
        (center[0] + size / 2, center[1] + size / 3)
    ], curvy=True, tag=tag)
Ejemplo n.º 7
0
def make_turtle(canvas, center, size=100, tag="turtle", fill="green"):
    tag = 'turtle_' + str(len(stuff))
    eye_width = eye_height = size /15
    utilities.make_oval(canvas,center,size/1.5,size,color="brown",tag=tag)
    utilities.make_circle(canvas, (center[0]-(0.73*size),center[1]- size/2.5),size/4.5, color=fill, tag=tag)
    utilities.make_circle(canvas, (center[0]+(0.73*size),center[1]- size/2.5),size/4.5, color=fill, tag=tag)
    utilities.make_circle(canvas, (center[0]-(0.73*size),center[1]+ size/2.5),size/4.5, color=fill, tag=tag)
    utilities.make_circle(canvas, (center[0]+(0.73*size),center[1]+ size/2.5),size/4.5, color=fill, tag=tag)
    utilities.make_circle(canvas, (center[0],center[1]-size),size/4, color=fill, tag=tag)
    utilities.make_oval(canvas, (center[0]-size/4,center[1]-size), eye_width, eye_height, color='black', tag=tag)
    utilities.make_oval(canvas, (center[0]+size/4,center[1]-size), eye_width, eye_height, color='black', tag=tag)
    stuff.append({
        'tag': tag,
        'speed': random.uniform(1, 5)
    })
Ejemplo n.º 8
0
import utilities

canvas = utilities.create_canvas_window()

##################################################################################
# Your code below this line...

f = open(utilities.get_file_path('bubbles.csv'))
for line in f.readlines():
    line = line.replace('\n', '')
    items = line.split(',')
    x = int(items[0])
    y = int(items[1])
    radius = int(items[2])
    # print([x, y, radius])
    utilities.make_circle(canvas, (x, y), radius)

# Your code above this line
##################################################################################
canvas.mainloop()
Ejemplo n.º 9
0
window_width = gui.winfo_screenwidth()
window_height = gui.winfo_screenheight()
canvas = Canvas(gui,
                width=window_width,
                height=window_height,
                background='white')
canvas.pack()
##################################################################################
# Your code below this line...

# Your job: Modify the code below so that as
# you loop through each line of the file, you:
# 1. create a variable called "center" that
#    stores the first and second number in the line
#    as a (tuple of ints).
# 2. Create a variable called "radius" that stores the
#    third number in the line.
# 3. Passes the center and radius variables into the
#    utilities.make_circle function as arguments.

f = open(utilities.get_file_path('bubbles.csv'))
for line in f.readlines():
    print(line)

utilities.make_circle(canvas, (30, 90), 50)
utilities.make_circle(canvas, (300, 490), 10)
utilities.make_circle(canvas, (530, 150), 40)

# Your code above this line
##################################################################################
canvas.mainloop()
Ejemplo n.º 10
0
# 3. Initialize close button:
# read about buttons:
# https://www.labspoint.com/python3/tk_button.htm
my_name = StringVar()
Entry(mainframe, textvariable=my_name).grid(column=0, row=0, sticky=E)

Button(mainframe,
       padx=5,
       pady=5,
       text='ADD MESSAGE',
       command=add_message_to_canvas).grid(column=1, row=0, sticky=E)

# 4. initialize canvas:
canvas_width = gui.winfo_screenwidth()
canvas_height = gui.winfo_screenheight() - 100
canvas = Canvas(gui,
                width=canvas_width,
                height=canvas_height,
                background='white')
canvas.grid(column=0, row=1, sticky=W)

utilities.make_circle(canvas, (200, 200), 20, color='hotpink', tag='my_circle')

while True:
    utilities.update_position_by_tag(canvas, 'my_circle', 2, 0)
    time.sleep(0.01)
    gui.update()

########################## YOUR CODE ABOVE THIS LINE ##############################
# makes sure the canvas keeps running:
canvas.mainloop()
Ejemplo n.º 11
0
import utilities
import keycodes

gui = Tk()
gui.title('Keyboard Event Handler')

# initialize canvas:
window_width = gui.winfo_screenwidth()
window_height = gui.winfo_screenheight()
canvas = Canvas(gui, width=window_width, height=window_height, background='white')
canvas.pack()

########################## YOUR CODE BELOW THIS LINE ##############################
KEY_PRESS = '<Key>'

utilities.make_circle(canvas, (window_width/2, window_height/2), 50, color='hotpink', tag='circle')


def move_circle(event):
    distance = 10
    if event.keycode == keycodes.get_up_keycode():
        utilities.update_position_by_tag(canvas, tag='circle', x=0, y=-distance)
    elif event.keycode == keycodes.get_down_keycode():
        utilities.update_position_by_tag(canvas, tag='circle', x=0, y=distance)
    elif event.keycode == keycodes.get_left_keycode():
        utilities.update_position_by_tag(canvas, tag='circle', x=-distance, y=0)
    elif event.keycode == keycodes.get_right_keycode():
        utilities.update_position_by_tag(canvas, tag='circle', x=distance, y=0)
    else:
        print('Keycode:', event.keycode, 'not handled by this if/elif/else statement.')
Ejemplo n.º 12
0
max_speed = social_activity

# set up visual info
person_size = 5
healthy_colour = '#00f708'
infected_colour = '#e81313'
removed_colour = '#3c5980'

# the list will contain all the persons being simulated
# in particular, each list item/element will be another list
# containing the person's location, speed and
# whether the person is healthy, infected, or removed,
# and how many days since infection

person_list = []
counter = 0

xloc = random.uniform(0, window_width)
yloc = random.uniform(0, window_height)
days = 0
person_list.append([xloc, yloc, 0, 0, 'infected', days])
utilities.make_circle(canvas, (xloc, yloc),
                      radius=person_size,
                      color=infected_colour,
                      tag="person" + str(counter))
counter += 1

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

# makes sure the canvas keeps running:
canvas.mainloop()
Ejemplo n.º 13
0
def moving_circle_left(canvas,initial_center:tuple, size, fill="green", tag="leafyleft"):
    utilities.make_circle(canvas, initial_center,size, color=fill, tag=tag)
    utilities.make_circle(canvas, (initial_center[0]-size*1.414,initial_center[1]-size*1.414),size,color=fill)
    utilities.make_circle(canvas, (initial_center[0]-size*1.414*2,initial_center[1]-size*1.414*2),size,color=fill)
    utilities.make_circle(canvas, (initial_center[0]-size*1.414*3,initial_center[1]-size*1.414*3),size,color=fill)
    utilities.make_circle(canvas, (initial_center[0]-size*1.414*4,initial_center[1]-size*1.414*4),size,color=fill)
    utilities.make_circle(canvas, (initial_center[0]-size*1.414*5,initial_center[1]-size*1.414*5),size,color=fill)
Ejemplo n.º 14
0
def make_flower(canvas,center,size=100,tag="flower",fill="yellow"):
    for i in range(0,360,30):
        make_petal(canvas, center,size,angle=i)
    utilities.make_circle(canvas,center,size/4,color="brown", tag=tag)
Ejemplo n.º 15
0
import utilities

canvas = utilities.create_canvas_window()
##################################################################################
# Your code below this line...

# Your job: Modify the code below so that as
# you loop through each line of the file, you:
# 1. create a variable called "center" that
#    stores the first and second number in the line
#    as a (tuple of ints).
# 2. Create a variable called "radius" that stores the
#    third number in the line.
# 3. Passes the center and radius variables into the
#    utilities.make_circle function as arguments.

f = open(utilities.get_file_path('bubbles.csv'))
for line in f.readlines():
    print(line)

utilities.make_circle(canvas, (100, 100), 100)

# Your code above this line
##################################################################################
canvas.mainloop()
Ejemplo n.º 16
0
def make_circle(event):
    utilities.make_circle(canvas, (event.x, event.y),
                          20,
                          color='hotpink',
                          tag='circle')
    canvas.focus_set()
Ejemplo n.º 17
0
import math
import time

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

center_x = 200
center_y = 200
distance_from_center = 120
center = (center_x, center_y)
center_creature = (center_x, center_y - distance_from_center)
make_creature(canvas, center_creature, 60, fill='hotpink', tag='creature')
make_circle(canvas, center, 10, color='black')
counter = 0
slow_factor = 250
while True:
    # calculate new position of x and y
    radians = counter / slow_factor
    dy = distance_from_center / slow_factor * math.sin(radians)
    dx = distance_from_center / slow_factor * math.cos(radians)
    update_position_by_tag(canvas, tag='creature', x=dx, y=dy)
    counter += 1
    gui.update()
    time.sleep(.01)


########################## YOUR CODE ABOVE THIS LINE ############################## 
canvas.mainloop()