Advertisement
Guest User

Untitled

a guest
Oct 17th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. from turtle import Turtle
  2. from numpy import cos, sin, pi
  3.  
  4. t = Turtle()
  5. t.speed(100_000)
  6.  
  7.  
  8. def jump2next(pt: tuple):
  9.     t.penup()
  10.     t.goto(pt)
  11.     t.pendown()
  12.  
  13.  
  14. def pol2dec(r: float, phi: float) -> tuple:
  15.     x = r * cos(phi)
  16.     y = r * sin(phi)
  17.     return x, y
  18.  
  19.  
  20. def draw_circle(radius: int, x0: int=0, y0: int=0) ->None:
  21.     vertex_num = 10 + 5 * radius // 10
  22.     x, y = pol2dec(radius, 0)
  23.     jump2next((x0 + x, y0 + y))
  24.     for vn in range(vertex_num + 1):
  25.         angle = vn * 2 * pi / vertex_num
  26.         x, y = pol2dec(radius, angle)
  27.         t.goto((x0 + x,y0 + y))
  28.  
  29.  
  30. def draw_flower(num_petal = 5, size=200, x0=0, y0=0):
  31.     base_angle = 0
  32.     max_petal = num_petal
  33.     angle_inc = 2 * pi / max_petal
  34.     flower_radius = size
  35.     petal_radius = int(flower_radius * sin(angle_inc / 2))
  36.     for petal_n in range(max_petal):
  37.         angle = base_angle + petal_n * angle_inc
  38.         x, y = pol2dec(flower_radius, angle)
  39.         draw_circle(petal_radius, x0+x, y0+y)
  40.  
  41. draw_flower(5)
  42. draw_flower(7, 150, 300, 300)
  43. draw_flower(5, 10, -300, -300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement