Пример #1
0
def draw_state(statusList: list, x_pos=50, y_pos=50, width=250):
    canvas.clear()
    height = width  # высота поля равно ширине
    widKl = width // 3  # ширина клетки
    x = widKl // 2 + x_pos  # начальные координата середины клетки
    y = x
    index = 0  # индекс списка
    # отрисовка линий
    canvas.line_width(2)
    canvas.set_color('Grey')
    for n in [1, 2]:
        canvas.move_to(n * widKl + x_pos, 0 + y_pos)
        canvas.line_to(n * widKl + x_pos, height + y_pos)
        canvas.move_to(0 + x_pos, n * widKl + y_pos)
        canvas.line_to(width + x_pos, n * widKl + y_pos)

    canvas.line_width(5)
    for i in range(3):
        for j in range(3):
            el = statusList[index]
            index += 1
            # расчет координат середины текущей клетки
            _x = x + widKl * j
            _y = y + widKl * i
            if el is not None:
                if el == 'o':
                    canvas.set_color('Green')
                    canvas.circle(_x, _y, width * 0.1)
                if el == 'x':
                    canvas.set_color('Blue')
                    wNol = width * 0.1
                    canvas.move_to(_x - wNol, _y + wNol)
                    canvas.line_to(_x + wNol, _y - wNol)
                    canvas.move_to(_x - wNol, _y - wNol)
                    canvas.line_to(_x + wNol, _y + wNol)
Пример #2
0
def my_click(x, y):
    colors = ["Pink", 'Lime', 'Red', "Blue", 'Crimson', 'Gold', 'RosyBrown']
    a = enumerate(colors)
    for i in a:
        canvas.set_color(str(i[1]))
        b = range(15)
        canvas.circle(x, y, b[i[0]])
        # canvas.fill_circle(x, y, 15)
    canvas.draw()
Пример #3
0
def paint_draw():
    global paint_obj
    for el in paint_obj:
        if el[0] == 'point':
            canvas.fill_style(el[3])
            canvas.fill_circle(el[1], el[2], 2)
        if el[0] == 'line':
            canvas.set_color(el[5])
            canvas.move_to(el[1], el[2])
            canvas.line_to(el[3], el[4])
        if el[0] == 'rect':
            if el[6]:
                canvas.fill_style(el[5])
                canvas.fill_rect(el[1], el[2], el[3], el[4])
            else:
                canvas.set_color(el[5])
                canvas.stroke_rect(el[1], el[2], el[3], el[4])
        if el[0] == 'circle':
            if el[5]:
                canvas.fill_style(el[4])
                canvas.fill_circle(el[1], el[2], el[3])
            else:
                canvas.set_color(el[4])
                canvas.circle(el[1], el[2], el[3])
Пример #4
0
import time
import canvas
import random

colors = ("Blue","Red","Fuchsia","Green","Purple","Black")

while True:
    x = random.randint(0, 350)
    y = random.randint(0, 350)

    for r in range(150, 185, 5):
        randomColors = random.choice(colors)

        canvas.circle(x,y, r)
        canvas.set_color(randomColors)

        canvas.draw()
        time.sleep(0.05)
        
words = string.split(' ')
numbers = []
for w in words:
    if w.isdigit():
        numbers.append(int(w))
        numbers.sort()
        print(numbers)

# l_107
import canvas
for x in range(7, 180, 7):
    if x % 2 == 0:
        canvas.set_color("Red")
    else:
        canvas.set_color("Grey")
    canvas.circle(175, 175, x)

canvas.draw()

#Letpy's code
# import canvas

# for i in range(7,180,7):
#     if i % 2 == 0:
#         canvas.set_color('Red')
#     else:
#         canvas.set_color('Grey')
#     canvas.circle(175, 175, i)
# canvas.draw()

# l_112
Пример #6
0
import canvas
import time
import random
circles = []
for i in range (5):
    x = random.randint(20,330)
    y = random.randint(20,330)
    dx = random.choice([-6,5])
    dy = random.choice([-6,5])
    catalog = {'x': x,'y': y,'dx': dx,'dy': dy}
    circles.append(catalog)
while True:
    canvas.clear()
    for k in circles:
            k['x'] +=  k['dx']
            if k['x'] > 330 or k['x'] < 20:
                k['dx'] = - k['dx']
            k['y'] += k['dy']
            if k['y'] > 330 or k['y'] < 20:
                k['dy'] = - k['dy']
            canvas.circle(k['x'],k['y'],20)
            canvas.draw()
    time.sleep(0.01)
Пример #7
0
def my_click(x, y):
    canvas.circle(x, y, 15)
    canvas.draw()
Пример #8
0
        
circles = []
for i in range(5):
    circle = {
        'x': random.randint(20, 330),
        'y': random.randint(20, 330),
        'dx': random.choice([5,-5]),
        'dy': random.choice([5,-5]),
        'color': colors[i]
    }
    circles.append(circle)
    
while True :
    canvas.clear()
    
    for circle in circles:
        canvas.set_color(circle['color'])
        if circle['x']> 330 or circle['x'] < 20:
            circle['dx'] *= -1
        if circle['y']> 330 or circle['y'] < 20:
            circle['dy'] *= -1
            
        circle["x"] += circle["dx"]
        circle["y"] += circle["dy"]
        canvas.circle(circle["x"], circle["y"], 20)
        
    canvas.draw()
    time.sleep(0.01)

            
    
import canvas
import time

rad = 180
for i in range(7, rad, 7):
    canvas.circle(175, 175, i)
    if i % 2 == 0:
        canvas.set_color("Red")
    else:
        canvas.set_color("Grey")
    canvas.draw()