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()
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)
def calc(x, y, width, height, focus): global calc_butt global init_calc global buff global lcd_value global memory border_col, background_content, text_col, header_col = theme[theme_active] canvas.set_color(border_col) canvas.stroke_rect(x + 5, y + 5, width - 10, 30) canvas.fill_style('Black') canvas.fill_text(lcd_value, x + width - 10, y + 5 + 30 - 7, 'Tahoma', 22, 'right') if memory[0] != 0: canvas.fill_style('Black') canvas.fill_text('M', x + 8, y + 18, 'Tahoma', 14, 'left') x_but, y_but, width_but, height_but = x + 5, y + 40, (width - 10) / len( calc_butt[0]) - 4, (height - 45) / len(calc_butt) - 4 border = 5 click, x_click, y_click = buff if not init_calc: for i in range(len(calc_butt)): for j in range(len(calc_butt[0])): x_b = x_but + (width_but + border) * j y_b = y_but + (height_but + border) * i button(x_b, y_b, width_but, height_but, calc_butt[i][j][0], False) calc_butt[i][j][1] = x_b calc_butt[i][j][2] = y_b init_calc = True else: for i in range(len(calc_butt)): for j in range(len(calc_butt[0])): cap, x_but, y_but = calc_butt[i][j] button(x_but, y_but, width_but, height_but, cap, False) if click and focus: if x_but < x_click < x_but + width_but and y_but < y_click < y_but + height_but: calc_handler(cap) buff[0] = False
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])
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)
# l_105 string = input() 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)
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()
def window(x, y, width, height, caption, focus, target): global data_property global buff global stack global message_listering border_col, background_content, text_col, header_col = theme[theme_active] border = 3 height_caption = 20 margin_text = 5 canvas.fill_style('Black') canvas.fill_rect(x + 1, y + 1, width, height) # Тень окна canvas.fill_style(border_col) canvas.fill_rect(x, y, width, height) # Основное окно if focus: canvas.fill_style(header_col) else: canvas.fill_style('Grey') canvas.fill_rect(x + border, y + border, width - border * 2, height_caption) # Окно шапки canvas.fill_style('Black') canvas.fill_text(caption, x + border + margin_text + 1, y + border + 15 + 1, 'Tahoma', 14, 'left') # тень текста шапки canvas.fill_style(text_col) canvas.fill_text(caption, x + border + margin_text, y + border + 15, 'Tahoma', 14, 'left') # текст шапки canvas.fill_style(background_content) canvas.fill_rect(x + border, y + border * 2 + height_caption, width - border * 2, height - border * 3 - height_caption) # фон окна, контента x_but_close = x + width - margin_text - 14 + 1 y_but_close = y + 6 canvas.fill_style('Black') canvas.fill_rect(x_but_close + 1, y_but_close + 1, 14, 14) canvas.fill_style('DarkGray') canvas.fill_rect(x_but_close, y_but_close, 14, 14) canvas.set_color('Black') canvas.line_width(2) canvas.radius_line(x_but_close + 2, y_but_close + 2, 135, 13) canvas.radius_line(x_but_close + 2 + 9, y_but_close + 2, 225, 13) # Реализацию вызовов нужных функций можно переделать с использованием передачи параметра-функции, возможно доработаю в следующих версиях if data_property[target][6] == 'Paint': paint(x + border, y + border * 2 + height_caption, width - border * 2, height - border * 3 - height_caption, focus) if data_property[target][6] == 'Color': paint_color_window(x + border, y + border * 2 + height_caption, width - border * 2, height - border * 3 - height_caption, focus) if data_property[target][6] == 'Calc': calc(x + border, y + border * 2 + height_caption, width - border * 2, height - border * 3 - height_caption, focus) # Обработчик закрытия окна click, x_click, y_click = buff if click: if x_but_close + 14 > x_click > x_but_close and y_but_close + 14 > y_click > y_but_close: message_listering.append(['window', caption, 'close']) buff[0] = False if click and not focus: if x < x_click < x + width and y < y_click < y + height_caption: message_listering.append(['window', caption, 'enable_focus']) buff[0] = False