Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from turtle import *
- from math import degrees, radians, sin, cos, atan, sqrt
- def main():
- reset()
- #speed(0)
- w = 500.
- h = 200.
- draw_rect(w, h, 0)
- draw_rect(w, h, 15)
- draw_rect(w, h, 90)
- draw_rect(w, h, 105)
- draw_rect(w, h, 180)
- draw_rect(w, h, 360)
- def draw_rect(w, h, angle):
- r = sqrt(w*w/4 + h*h/4)
- theta1 = degrees(atan((h/2) / (w/2)))
- theta2 = -theta1
- theta3 = theta1 - 180
- theta4 = 180 - theta1
- theta1 += angle
- theta2 += angle
- theta3 += angle
- theta4 += angle
- x1 = cos(radians(theta1)) * r
- y1 = sin(radians(theta1)) * r
- x2 = cos(radians(theta2)) * r
- y2 = sin(radians(theta2)) * r
- x3 = cos(radians(theta3)) * r
- y3 = sin(radians(theta3)) * r
- x4 = cos(radians(theta4)) * r
- y4 = sin(radians(theta4)) * r
- penup()
- goto(x1, y1)
- pendown()
- goto(x2, y2)
- goto(x3, y3)
- goto(x4, y4)
- goto(x1, y1)
- penup()
- if __name__ == "__main__":
- main()
- hideturtle()
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement