Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # tk_Bauhaus.py
- import tkinter as tk
- import random
- GRID_SIZE = 10
- CELL_SIZE = 60
- OUTER_RADIUS = CELL_SIZE
- THICKNESS = OUTER_RADIUS // 2
- INNER_RADIUS = OUTER_RADIUS - THICKNESS
- fg_colors = ["#f4ac14", "#f19bc2", "#b12223"]
- bg_colors = ["#458b97", "#beab8a", "#ff2621"]
- root = tk.Tk()
- root.title("Bauhaus")
- canvas = tk.Canvas(root, width=GRID_SIZE * CELL_SIZE, height=GRID_SIZE * CELL_SIZE, bg="white")
- canvas.pack()
- def draw_quarter_ring(x, y, orientation, fg_color):
- if orientation == 0: # Top-left
- outer = (x, y, x + OUTER_RADIUS * 2, y + OUTER_RADIUS * 2)
- inner = (x + THICKNESS, y + THICKNESS, x + (OUTER_RADIUS * 2 - THICKNESS), y + (OUTER_RADIUS * 2 - THICKNESS))
- start = 90
- elif orientation == 1: # Top-right
- outer = (x + CELL_SIZE - OUTER_RADIUS * 2, y, x + CELL_SIZE, y + OUTER_RADIUS * 2)
- inner = (x + CELL_SIZE - OUTER_RADIUS * 2 + THICKNESS, y + THICKNESS, x + CELL_SIZE - THICKNESS, y + OUTER_RADIUS * 2 - THICKNESS)
- start = 0
- elif orientation == 2: # Bottom-right
- outer = (x + CELL_SIZE - OUTER_RADIUS * 2, y + CELL_SIZE - OUTER_RADIUS * 2, x + CELL_SIZE, y + CELL_SIZE)
- inner = (x + CELL_SIZE - OUTER_RADIUS * 2 + THICKNESS, y + CELL_SIZE - OUTER_RADIUS * 2 + THICKNESS, x + CELL_SIZE - THICKNESS, y + CELL_SIZE - THICKNESS)
- start = 270
- elif orientation == 3: # Bottom-left
- outer = (x, y + CELL_SIZE - OUTER_RADIUS * 2, x + OUTER_RADIUS * 2, y + CELL_SIZE)
- inner = (x + THICKNESS, y + CELL_SIZE - OUTER_RADIUS * 2 + THICKNESS, x + OUTER_RADIUS * 2 - THICKNESS, y + CELL_SIZE - THICKNESS)
- start = 180
- canvas.create_arc(outer, start=start, extent=90, fill=fg_color, outline=fg_color)
- bg_color = random.choice(bg_colors)
- canvas.create_arc(inner, start=start, extent=90, fill=bg_color, outline=bg_color)
- def draw_grid():
- canvas.delete("all")
- for row in range(GRID_SIZE):
- for col in range(GRID_SIZE):
- x = col * CELL_SIZE
- y = row * CELL_SIZE
- orientation = random.randint(0, 3)
- fg_color = random.choice(fg_colors)
- bg_color = random.choice(bg_colors)
- canvas.create_rectangle(x, y, x + CELL_SIZE, y + CELL_SIZE, fill=bg_color, outline=bg_color)
- draw_quarter_ring(x, y, orientation, fg_color)
- root.bind("<space>", lambda event: draw_grid())
- draw_grid()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment