Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- import math
- def hexagone(point, longueur, col, centre, rayon):
- turtle.penup()
- turtle.goto(deformation(point, centre, rayon))
- turtle.pendown()
- x, y = point
- for i in range(3):
- p1 = x + longueur*(-1/2), y + longueur*(-1)**(i+1)*3**(1/2)/2
- p2 = x + longueur*(1/2-3/2*(i == 2)), y + longueur*(-3**(1/2)/2*(i == 0)+3**(1/2)/2*(i == 1))
- p3 = x + longueur*(1-3/2*(i == 2)), y + longueur*3**(1/2)/2*(i == 2)
- turtle.color(col[i])
- turtle.begin_fill()
- turtle.goto(deformation(p1, centre, rayon))
- turtle.goto(deformation(p2, centre, rayon))
- turtle.goto(deformation(p3, centre, rayon))
- turtle.goto(deformation(point, centre, rayon))
- turtle.end_fill()
- def deformation(point, centre, rayon):
- x0, y0, z0 = centre
- x, y = point
- if rayon > abs(z0):
- ra = (rayon ** 2 - z0 ** 2) ** (1 / 2)
- if (x-x0)**2+(y-y0)**2 < ra**2:
- r = ((x - x0) ** 2 + (y - y0) ** 2) ** (1 / 2)
- r2 = rayon * math.sin(r / ra * math.acos(abs(z0) / rayon))
- x, y = x0 + r2 / r * (x - x0), y0 + r2 / r * (y - y0)
- point = (x, y)
- return point
- def pavage(inf_gauche, sup_droit, longueur, col, centre, rayon):
- n_hor = 2*round((sup_droit - inf_gauche-longueur*1.5)*2/(5*longueur))-1
- n_ver = round((sup_droit - inf_gauche-3**(1/2)*longueur)/(longueur*3**(1/2)))
- for i in range(n_hor):
- for j in range(n_ver):
- hexagone((inf_gauche + longueur*i*1.5, inf_gauche + longueur*3**(1/2)*((i % 2 == 1)/2 + j))
- , longueur, col, centre, rayon)
- inf_gauche = int(input('inf_gauche'))
- sup_droit = int(input('sup_droit'))
- longueur = float(input('longueur'))
- col = (input('c1'), input('c2'), input('c3'))
- col = (col[2], col[0], col[1])
- centre = (float(input('x0')), float(input('y0')), float(input('z0')))
- rayon = float(input('rayon'))
- pavage(inf_gauche, sup_droit, longueur, col, centre, rayon)
- turtle.speed(0)
- turtle.done()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement