fuccpuff

Untitled

Mar 3rd, 2025 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. import tkinter as tk
  2. import math
  3.  
  4. def draw_gradient_background(canvas, width, height, start_color="#E0F7FA", end_color="#ffffff", steps=100):
  5. def hex_to_rgb(hex_color):
  6. hex_color = hex_color.lstrip("#")
  7. return tuple(int(hex_color[i:i + 2], 16) for i in (0, 2, 4))
  8. start_rgb = hex_to_rgb(start_color)
  9. end_rgb = hex_to_rgb(end_color)
  10. delta_r = (end_rgb[0] - start_rgb[0]) / steps
  11. delta_g = (end_rgb[1] - start_rgb[1]) / steps
  12. delta_b = (end_rgb[2] - start_rgb[2]) / steps
  13. strip_height = height / steps
  14. for i in range(steps):
  15. r = int(start_rgb[0] + delta_r * i)
  16. g = int(start_rgb[1] + delta_g * i)
  17. b = int(start_rgb[2] + delta_b * i)
  18. color = f"#{r:02x}{g:02x}{b:02x}"
  19. canvas.create_rectangle(0, i * strip_height, width, (i + 1) * strip_height, outline=color, fill=color)
  20.  
  21. def draw_tulip(canvas, x, y, scale=1.0, petal_color="#FF69B4", stem_color="#228B22"):
  22. canvas.create_oval(x - 20 * scale, y - 40 * scale, x + 10 * scale, y, fill=petal_color, outline=petal_color)
  23. canvas.create_oval(x - 10 * scale, y - 40 * scale, x + 20 * scale, y, fill=petal_color, outline=petal_color)
  24. canvas.create_oval(x - 5 * scale, y - 30 * scale, x + 5 * scale, y - 20 * scale, fill="yellow", outline="yellow")
  25. canvas.create_line(x, y, x, y + 50 * scale, fill=stem_color, width=3 * scale)
  26. canvas.create_polygon(x, y + 20 * scale, x - 25 * scale, y + 35 * scale, x - 10 * scale, y + 40 * scale, fill=stem_color, outline=stem_color)
  27. canvas.create_polygon(x, y + 20 * scale, x + 25 * scale, y + 35 * scale, x + 10 * scale, y + 40 * scale, fill=stem_color, outline=stem_color)
  28.  
  29. def draw_heart(canvas, x, y, size=30, fill_color="#FF0000"):
  30. canvas.create_arc(x - size, y - size, x, y, start=0, extent=180, fill=fill_color, outline=fill_color)
  31. canvas.create_arc(x, y - size, x + size, y, start=0, extent=180, fill=fill_color, outline=fill_color)
  32. canvas.create_polygon(x - size, y - (size // 2), x + size, y - (size // 2), x, y + (size // 1.5), fill=fill_color, outline=fill_color)
  33.  
  34. def main():
  35. root = tk.Tk()
  36. root.title("Поздравление с 8 марта!")
  37. root.resizable(False, False)
  38. canvas_width = 600
  39. canvas_height = 450
  40. canvas = tk.Canvas(root, width=canvas_width, height=canvas_height)
  41. canvas.pack()
  42. draw_gradient_background(canvas, width=canvas_width, height=canvas_height, start_color="#E0F7FA", end_color="#fff8e1", steps=150)
  43. greeting_text = ("С 8 МАРТА!\nПусть весна принесёт\nрадость, красоту и вдохновение!\nБудьте всегда любимы и счастливы!")
  44. canvas.create_text(canvas_width // 2, 60, text=greeting_text, font=("Helvetica", 18, "bold"), fill="#4A148C", justify="center")
  45. draw_tulip(canvas, x=220, y=220, scale=1.3, petal_color="#FF69B4", stem_color="#2E8B57")
  46. draw_tulip(canvas, x=300, y=200, scale=1.5, petal_color="#FF1493", stem_color="#006400")
  47. draw_tulip(canvas, x=380, y=220, scale=1.3, petal_color="#FF85A1", stem_color="#228B22")
  48. draw_heart(canvas, x=120, y=100, size=25, fill_color="#F06292")
  49. draw_heart(canvas, x=480, y=110, size=25, fill_color="#F06292")
  50. draw_heart(canvas, x=180, y=350, size=35, fill_color="#EC407A")
  51. draw_heart(canvas, x=420, y=350, size=35, fill_color="#EC407A")
  52. draw_heart(canvas, x=300, y=370, size=15, fill_color="#F50057")
  53. draw_heart(canvas, x=260, y=140, size=15, fill_color="#F50057")
  54. draw_heart(canvas, x=340, y=140, size=15, fill_color="#F50057")
  55. root.mainloop()
  56.  
  57. if __name__ == "__main__":
  58. main()
  59.  
Advertisement
Add Comment
Please, Sign In to add comment