Advertisement
tinyevil

Untitled

Dec 11th, 2019
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. from turtle import Turtle
  2. import math
  3.  
  4.  
  5. turtle = Turtle()
  6. turtle.shape("turtle")
  7.  
  8.  
  9. def draw_circle(radius):
  10.     draw_arc(radius, 360)
  11.  
  12.  
  13. def draw_arc(radius, angle):
  14.     circle_length = angle / 180 * math.pi * radius
  15.     max_segment_length = 2
  16.     segments = int(max(1, circle_length // max_segment_length))
  17.     segment_length = circle_length / segments
  18.     segment_rotation = angle / segments
  19.     for i in range(segments):
  20.         turtle.forward(segment_length)
  21.         turtle.left(segment_rotation)
  22.  
  23.  
  24. def jump_forward(distance):
  25.     turtle.penup()
  26.     turtle.forward(distance)
  27.     turtle.pendown()
  28.  
  29.  
  30. def draw_gear(hole_radius, ring_width, pips_height, pips_count, pip_boldness):
  31.     jump_forward(hole_radius)
  32.     turtle.left(90)
  33.     draw_circle(hole_radius)
  34.     turtle.right(90)
  35.     jump_forward(ring_width)
  36.  
  37.     inner_radius = ring_width + hole_radius
  38.     outter_radius = inner_radius + pips_height
  39.  
  40.     segment_arc = 360 / pips_count
  41.     pip_arc = pip_boldness * segment_arc
  42.     hole_arc = segment_arc - pip_arc
  43.  
  44.     turtle.left(90)
  45.     for i in range(pips_count):
  46.         draw_arc(inner_radius, hole_arc)
  47.         turtle.right(90)
  48.         turtle.forward(pips_height)
  49.         turtle.left(90)
  50.         draw_arc(outter_radius, pip_arc)
  51.         turtle.left(90)
  52.         turtle.forward(pips_height)
  53.         turtle.right(90)
  54.  
  55.  
  56. turtle.penup()
  57. turtle.goto(0, 0)
  58. turtle.pendown()
  59. draw_gear(20, 40, 15, 8, 0.5)
  60.  
  61.  
  62. turtle.penup()
  63. turtle.goto(120, -100)
  64. turtle.pendown()
  65. draw_gear(10, 50, 5, 16, 0.8)
  66.  
  67.  
  68. turtle.penup()
  69. turtle.goto(70, 90)
  70. turtle.pendown()
  71. draw_gear(16, 4, 10, 9, 0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement