Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. import turtle
  2. import math
  3.  
  4.  
  5. def hexagone(point, longueur, col, centre, rayon):
  6. turtle.penup()
  7. turtle.goto(deformation(point, centre, rayon))
  8. turtle.pendown()
  9. x, y = point
  10. for i in range(3):
  11. p1 = x + longueur*(-1/2), y + longueur*(-1)**(i+1)*3**(1/2)/2
  12. p2 = x + longueur*(1/2-3/2*(i == 2)), y + longueur*(-3**(1/2)/2*(i == 0)+3**(1/2)/2*(i == 1))
  13. p3 = x + longueur*(1-3/2*(i == 2)), y + longueur*3**(1/2)/2*(i == 2)
  14. turtle.color(col[i])
  15. turtle.begin_fill()
  16. turtle.goto(deformation(p1, centre, rayon))
  17. turtle.goto(deformation(p2, centre, rayon))
  18. turtle.goto(deformation(p3, centre, rayon))
  19. turtle.goto(deformation(point, centre, rayon))
  20. turtle.end_fill()
  21.  
  22.  
  23. def deformation(point, centre, rayon):
  24. x0, y0, z0 = centre
  25. x, y = point
  26. if rayon > abs(z0):
  27. ra = (rayon ** 2 - z0 ** 2) ** (1 / 2)
  28. if (x-x0)**2+(y-y0)**2 < ra**2:
  29. r = ((x - x0) ** 2 + (y - y0) ** 2) ** (1 / 2)
  30. r2 = rayon * math.sin(r / ra * math.acos(abs(z0) / rayon))
  31. x, y = x0 + r2 / r * (x - x0), y0 + r2 / r * (y - y0)
  32. point = (x, y)
  33.  
  34. return point
  35.  
  36.  
  37. def pavage(inf_gauche, sup_droit, longueur, col, centre, rayon):
  38. n_hor = 2*round((sup_droit - inf_gauche-longueur*1.5)*2/(5*longueur))-1
  39. n_ver = round((sup_droit - inf_gauche-3**(1/2)*longueur)/(longueur*3**(1/2)))
  40. for i in range(n_hor):
  41. for j in range(n_ver):
  42. hexagone((inf_gauche + longueur*i*1.5, inf_gauche + longueur*3**(1/2)*((i % 2 == 1)/2 + j))
  43. , longueur, col, centre, rayon)
  44.  
  45.  
  46. inf_gauche = int(input('inf_gauche'))
  47. sup_droit = int(input('sup_droit'))
  48. longueur = float(input('longueur'))
  49. col = (input('c1'), input('c2'), input('c3'))
  50. col = (col[2], col[0], col[1])
  51. centre = (float(input('x0')), float(input('y0')), float(input('z0')))
  52. rayon = float(input('rayon'))
  53. pavage(inf_gauche, sup_droit, longueur, col, centre, rayon)
  54. turtle.speed(0)
  55.  
  56.  
  57. turtle.done()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement