Advertisement
pamalau

Untitled

Feb 7th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. from turtle import Turtle, Screen
  2. from random import randint
  3. import math #Explore specific import ?
  4.  
  5. def randomColor():
  6.     return (randint(20,255), randint(20,255), randint(20,255))
  7.    
  8. def draw_dot(name,radius, color,x,y):
  9.     name.penup()
  10.     name.setx(x)
  11.     name.sety(y)
  12.     name.pendown()
  13.     name.color(color)
  14.     name.dot(radius * 2)
  15.    
  16. def drawPolygon (ttl, xpos, ypos, num_side, radius, fill):
  17.     sideLen = 2 * radius * math.sin (math.pi / num_side)
  18.     angle = 360 / num_side
  19.     ttl.penup()
  20.     ttl.goto (xpos, ypos)
  21. #    if fill == 1:
  22. #      ttl.fillcolor(ttl.pencolor())  
  23. #      ttl.begin_fill()
  24.     ttl.pendown()
  25.     for iter in range (num_side):
  26.         ttl.forward (sideLen)
  27.         ttl.left (angle)
  28. #    if fill == 1:
  29. #        ttl.end_fill()
  30.  
  31. tina = Turtle()
  32. #draw_dot(tina,50,"blue",0,0);
  33. #tina.position()
  34.  
  35. # create a turtle object
  36. scr = Screen()
  37.  
  38. #Needed to include the following to get the turtle
  39. #pencolor function to accept an R,G,B tuple
  40. #see https://docs.python.org/3/library/turtle.html#turtle.colormode
  41. scr.colormode(255)
  42. scr.bgcolor("black")
  43.  
  44. tina.speed(0)
  45.  
  46. #Not sure how to get the screen size. Just using these values
  47. #as they work on my screen
  48. x = -450
  49. y = +300
  50. delta = +105
  51. seg_size = +40
  52.  
  53. #draw polygons with number of sides from 3 to 10
  54. for ii in range(3,11):
  55.     tina.pencolor((randomColor()))
  56.     drawPolygon (tina, x, y, ii, seg_size, False)
  57.     x = x + delta
  58. x = -450    
  59. y = 150
  60.  
  61. #random number of sides
  62. for _ in range(4,12):
  63.     tina.pencolor((randomColor()))
  64.     drawPolygon (tina, x, y, randint(3,11), seg_size,False)
  65.     x = x + delta
  66. x = -450    
  67. y = 0
  68.  
  69. for jj in range(4,12):
  70.     tina.pencolor((randomColor()))
  71.     drawPolygon (tina, x, y, jj, seg_size,True)
  72.     x = x + delta
  73. x = -450    
  74. y = -150
  75.  
  76. #more circle like?
  77. for kk in range(10,18):
  78.     tina.pencolor((randomColor()))
  79.     drawPolygon (tina, x, y, kk, seg_size,True)
  80.     x = x + delta
  81. # persist drawing
  82. ttl.penup()
  83. ttl.goto(0,0)
  84. ttl.hideturtle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement