Advertisement
Guest User

JN

a guest
Sep 23rd, 2009
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from turtle import *
  4. from math import degrees, radians, sin, cos, atan, sqrt
  5.  
  6. def main():
  7.     reset()
  8.     #speed(0)
  9.    
  10.     w = 500.
  11.     h = 200.
  12.  
  13.     draw_rect(w, h, 0)
  14.     draw_rect(w, h, 15)
  15.    
  16.     draw_rect(w, h, 90)
  17.     draw_rect(w, h, 105)
  18.    
  19.     draw_rect(w, h, 180)
  20.     draw_rect(w, h, 360)
  21.    
  22. def draw_rect(w, h, angle):
  23.     r = sqrt(w*w/4 + h*h/4)
  24.    
  25.     theta1 = degrees(atan((h/2) / (w/2)))
  26.     theta2 = -theta1
  27.     theta3 = theta1 - 180
  28.     theta4 = 180 - theta1
  29.    
  30.     theta1 += angle
  31.     theta2 += angle
  32.     theta3 += angle
  33.     theta4 += angle
  34.    
  35.     x1 = cos(radians(theta1)) * r
  36.     y1 = sin(radians(theta1)) * r
  37.     x2 = cos(radians(theta2)) * r
  38.     y2 = sin(radians(theta2)) * r
  39.     x3 = cos(radians(theta3)) * r
  40.     y3 = sin(radians(theta3)) * r
  41.     x4 = cos(radians(theta4)) * r
  42.     y4 = sin(radians(theta4)) * r
  43.    
  44.     penup()
  45.     goto(x1, y1)
  46.     pendown()
  47.     goto(x2, y2)
  48.     goto(x3, y3)
  49.     goto(x4, y4)
  50.     goto(x1, y1)
  51.     penup()
  52.  
  53. if __name__ == "__main__":
  54.     main()
  55.     hideturtle()
  56.     mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement