rectangle.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. async def rounded_rectangle(
  2. rectangle,
  3. xy,
  4. corner_radius,
  5. fill=None,
  6. outline=None
  7. ):
  8. upper_left_point = xy[0]
  9. bottom_right_point = xy[1]
  10. rectangle.pieslice(
  11. [
  12. upper_left_point,
  13. (
  14. upper_left_point[0] + corner_radius * 2,
  15. upper_left_point[1] + corner_radius * 2,
  16. ),
  17. ],
  18. 180,
  19. 270,
  20. fill=fill,
  21. outline=outline,
  22. )
  23. rectangle.pieslice(
  24. [
  25. (
  26. bottom_right_point[0] - corner_radius * 2,
  27. bottom_right_point[1] - corner_radius * 2,
  28. ),
  29. bottom_right_point,
  30. ],
  31. 0,
  32. 90,
  33. fill=fill,
  34. outline=outline,
  35. )
  36. rectangle.pieslice(
  37. [
  38. (
  39. upper_left_point[0],
  40. bottom_right_point[1] - corner_radius * 2,
  41. ),
  42. (
  43. upper_left_point[0] + corner_radius * 2,
  44. bottom_right_point[1],
  45. ),
  46. ],
  47. 90,
  48. 180,
  49. fill=fill,
  50. outline=outline,
  51. )
  52. rectangle.pieslice(
  53. [
  54. (
  55. bottom_right_point[0] - corner_radius * 2,
  56. upper_left_point[1],
  57. ),
  58. (
  59. bottom_right_point[0],
  60. upper_left_point[1] + corner_radius * 2,
  61. ),
  62. ],
  63. 270,
  64. 360,
  65. fill=fill,
  66. outline=outline,
  67. )
  68. rectangle.rectangle(
  69. [
  70. (
  71. upper_left_point[0],
  72. upper_left_point[1] + corner_radius,
  73. ),
  74. (
  75. bottom_right_point[0],
  76. bottom_right_point[1] - corner_radius,
  77. ),
  78. ],
  79. fill=fill,
  80. outline=outline,
  81. )
  82. rectangle.rectangle(
  83. [
  84. (upper_left_point[0] + corner_radius, upper_left_point[1]),
  85. (bottom_right_point[0] - corner_radius, bottom_right_point[1]),
  86. ],
  87. fill=fill,
  88. outline=outline,
  89. )
  90. rectangle.line(
  91. [
  92. (
  93. upper_left_point[0] + corner_radius,
  94. upper_left_point[1],
  95. ),
  96. (
  97. bottom_right_point[0] - corner_radius,
  98. upper_left_point[1],
  99. ),
  100. ],
  101. fill=outline,
  102. )
  103. rectangle.line(
  104. [
  105. (
  106. upper_left_point[0] + corner_radius,
  107. bottom_right_point[1],
  108. ),
  109. (
  110. bottom_right_point[0] - corner_radius,
  111. bottom_right_point[1],
  112. ),
  113. ],
  114. fill=outline,
  115. )
  116. rectangle.line(
  117. [
  118. (
  119. upper_left_point[0],
  120. upper_left_point[1] + corner_radius,
  121. ),
  122. (
  123. upper_left_point[0],
  124. bottom_right_point[1] - corner_radius,
  125. ),
  126. ],
  127. fill=outline,
  128. )
  129. rectangle.line(
  130. [
  131. (
  132. bottom_right_point[0],
  133. upper_left_point[1] + corner_radius,
  134. ),
  135. (
  136. bottom_right_point[0],
  137. bottom_right_point[1] - corner_radius,
  138. ),
  139. ],
  140. fill=outline,
  141. )