here2share

# tk_Bauhaus.py

Oct 18th, 2025
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. # tk_Bauhaus.py
  2.  
  3. import tkinter as tk
  4. import random
  5.  
  6. GRID_SIZE = 10
  7. CELL_SIZE = 60
  8. OUTER_RADIUS = CELL_SIZE
  9. THICKNESS = OUTER_RADIUS // 2
  10. INNER_RADIUS = OUTER_RADIUS - THICKNESS
  11.  
  12. fg_colors = ["#f4ac14", "#f19bc2", "#b12223"]
  13. bg_colors = ["#458b97", "#beab8a", "#ff2621"]
  14.  
  15. root = tk.Tk()
  16. root.title("Bauhaus")
  17. canvas = tk.Canvas(root, width=GRID_SIZE * CELL_SIZE, height=GRID_SIZE * CELL_SIZE, bg="white")
  18. canvas.pack()
  19.  
  20. def draw_quarter_ring(x, y, orientation, fg_color):
  21.     if orientation == 0:  # Top-left
  22.         outer = (x, y, x + OUTER_RADIUS * 2, y + OUTER_RADIUS * 2)
  23.         inner = (x + THICKNESS, y + THICKNESS, x + (OUTER_RADIUS * 2 - THICKNESS), y + (OUTER_RADIUS * 2 - THICKNESS))
  24.         start = 90
  25.     elif orientation == 1:  # Top-right
  26.         outer = (x + CELL_SIZE - OUTER_RADIUS * 2, y, x + CELL_SIZE, y + OUTER_RADIUS * 2)
  27.         inner = (x + CELL_SIZE - OUTER_RADIUS * 2 + THICKNESS, y + THICKNESS, x + CELL_SIZE - THICKNESS, y + OUTER_RADIUS * 2 - THICKNESS)
  28.         start = 0
  29.     elif orientation == 2:  # Bottom-right
  30.         outer = (x + CELL_SIZE - OUTER_RADIUS * 2, y + CELL_SIZE - OUTER_RADIUS * 2, x + CELL_SIZE, y + CELL_SIZE)
  31.         inner = (x + CELL_SIZE - OUTER_RADIUS * 2 + THICKNESS, y + CELL_SIZE - OUTER_RADIUS * 2 + THICKNESS, x + CELL_SIZE - THICKNESS, y + CELL_SIZE - THICKNESS)
  32.         start = 270
  33.     elif orientation == 3:  # Bottom-left
  34.         outer = (x, y + CELL_SIZE - OUTER_RADIUS * 2, x + OUTER_RADIUS * 2, y + CELL_SIZE)
  35.         inner = (x + THICKNESS, y + CELL_SIZE - OUTER_RADIUS * 2 + THICKNESS, x + OUTER_RADIUS * 2 - THICKNESS, y + CELL_SIZE - THICKNESS)
  36.         start = 180
  37.  
  38.     canvas.create_arc(outer, start=start, extent=90, fill=fg_color, outline=fg_color)
  39.     bg_color = random.choice(bg_colors)
  40.     canvas.create_arc(inner, start=start, extent=90, fill=bg_color, outline=bg_color)
  41.  
  42. def draw_grid():
  43.     canvas.delete("all")
  44.     for row in range(GRID_SIZE):
  45.         for col in range(GRID_SIZE):
  46.             x = col * CELL_SIZE
  47.             y = row * CELL_SIZE
  48.             orientation = random.randint(0, 3)
  49.             fg_color = random.choice(fg_colors)
  50.             bg_color = random.choice(bg_colors)
  51.             canvas.create_rectangle(x, y, x + CELL_SIZE, y + CELL_SIZE, fill=bg_color, outline=bg_color)
  52.             draw_quarter_ring(x, y, orientation, fg_color)
  53.  
  54. root.bind("<space>", lambda event: draw_grid())
  55. draw_grid()
  56.  
  57. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment