Advertisement
iNoobAvicena

Flowers with Turtle

Jan 29th, 2022
1,084
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2. from turtle import Screen, Turtle
  3. # import turtle
  4. # import cv2
  5.  
  6. wn = Screen()
  7. # wn = turtle.Screen()
  8. wn.title('Buat Diva')
  9.  
  10. tina = Turtle()
  11. # tina = turtle.Turtle()
  12. tina.shape("circle")
  13. tina.color("black")
  14. tina.speed(0)
  15.  
  16. def drawSunflower(t, numseeds, numpetals, angle, cspread):
  17.     # t.fillcolor("red")
  18.     #ff6961
  19.     # t.fillcolor((255,105,97))
  20.     # col = input("Enter the color name or hex value of color(# RRGGBB): #ff6961")
  21.     t.fillcolor('#ff6961')
  22.     phi = angle * (math.pi / 180.0)
  23.    
  24.     for i in range (numseeds + numpetals):
  25.       # figure out the next x, y position
  26.       r = cspread * math.sqrt(i)
  27.       theta = i * phi
  28.       x = r * math.cos(theta)
  29.       y = r * math.sin(theta)
  30.  
  31.       # move the turtle and orient it correctly
  32.       t.penup()
  33.       t.goto(x, y)
  34.       t.setheading(i * angle)
  35.       t.pendown()
  36.  
  37.       if i <  numseeds:
  38.         t.stamp()
  39.       else:
  40.         drawPetal(t)
  41.          
  42. def drawPetal(t):
  43.     t.fillcolor("pink")
  44.     # t.fillcolor("white")
  45.     t.begin_fill()
  46.     t.right(20)
  47.     t.forward(70)
  48.     t.left(40)
  49.     t.forward(70)
  50.     t.left(140)
  51.     t.forward(70)
  52.     t.left(40)
  53.     t.forward(70)
  54.     t.end_fill()
  55.  
  56. drawSunflower(tina, 120, 40, 137.508, 4)
  57. tina.up()
  58. tina.goto(0, -240)
  59. tina.down()
  60. tina.write("hope u like it :D", align="center", font=("Comic Sans", 16, "normal"))
  61. tina.hideturtle()
  62. # cv2.destroyAllWindows()
  63.  
  64. wn.exitonclick()
  65.  
  66. # tina.hideturtle()
  67.  
  68.  
  69. # from turtle import Screen, Turtle, mainloop
  70.  
  71. # def draw_square(turtle):
  72. #     turtle.forward(100)
  73. #     turtle.right(90)
  74. #     turtle.forward(100)
  75. #     turtle.right(90)
  76. #     turtle.forward(100)
  77. #     turtle.right(90)
  78. #     turtle.forward(100)
  79. #     turtle.right(90)
  80.  
  81. # window = Screen()
  82. # window.bgcolor("red")
  83.  
  84. # brad = Turtle()
  85. # brad.shape("turtle")
  86. # brad.color("yellow")
  87. # brad.speed(2)
  88.  
  89. # draw_square(brad)
  90.  
  91. # mainloop()
Advertisement
RAW Paste Data Copied
Advertisement