How do I add depth to my Pentagonal trapezohedron?

I only have a little experience using turtle.

The shape unintentionally looks like an optical illusion, which was not my intended effect. I don’t know what the best approach to this is. I wanted to add some depth with shadows, but I don’t know if that’s possible. Any advice would be greatly appreciated.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import turtle
import math
# Setup
screen = turtle.Screen()
screen.bgcolor("light blue") # Set background
screen.title("Spinning Diamond")
t = turtle.Turtle()
t.speed(0)
t.hideturtle()
# vertices
vertices = [
[0, 0, 150], # Top vertex
[math.cos(2 * math.pi / 5) * 100, math.sin(2 * math.pi / 5) * 100, 50],
[math.cos(4 * math.pi / 5) * 100, math.sin(4 * math.pi / 5) * 100, 50],
[math.cos(6 * math.pi / 5) * 100, math.sin(6 * math.pi / 5) * 100, 50],
[math.cos(8 * math.pi / 5) * 100, math.sin(8 * math.pi / 5) * 100, 50],
[math.cos(10 * math.pi / 5) * 100, math.sin(10 * math.pi / 5) * 100, 50],
[math.cos(2 * math.pi / 5) * 100, math.sin(2 * math.pi / 5) * 100, -50],
[math.cos(4 * math.pi / 5) * 100, math.sin(4 * math.pi / 5) * 100, -50],
[math.cos(6 * math.pi / 5) * 100, math.sin(6 * math.pi / 5) * 100, -50],
[math.cos(8 * math.pi / 5) * 100, math.sin(8 * math.pi / 5) * 100, -50],
[math.cos(10 * math.pi / 5) * 100, math.sin(10 * math.pi / 5) * 100, -50],
[0, 0, -150] # Bottom vertex
]
faces = [
[0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1],
[6, 7, 11], [7, 8, 11], [8, 9, 11], [9, 10, 11], [10, 6, 11],
[1, 2, 7, 6], [2, 3, 8, 7], [3, 4, 9, 8], [4, 5, 10, 9], [5, 1, 6, 10]
]
# Define colors
colors = [
"red", "green", "blue", "yellow", "cyan",
"magenta", "orange", "purple", "lime", "pink",
"brown", "gray", "violet", "navy", "gold"
]
# Rotate around X-axis
def rotateX(point, angle):
rad = math.radians(angle)
cosA = math.cos(rad)
sinA = math.sin(rad)
y = point[1] * cosA - point[2] * sinA
z = point[1] * sinA + point[2] * cosA
return [point[0], y, z]
# Rotate around Y-axis
def rotateY(point, angle):
rad = math.radians(angle)
cosA = math.cos(rad)
sinA = math.sin(rad)
x = point[0] * cosA + point[2] * sinA
z = -point[0] * sinA + point[2] * cosA
return [x, point[1], z]
# Rotate around Z-axis
def rotateZ(point, angle):
rad = math.radians(angle)
cosA = math.cos(rad)
sinA = math.sin(rad)
x = point[0] * cosA - point[1] * sinA
y = point[0] * sinA + point[1] * cosA
return [x, y, point[2]]
def project(point):
distance = 300
factor = distance / (distance - point[2])
x = point[0] * factor
y = point[1] * factor
return [x, y]
# Draw Shape
def draw_polyhedron():
t.clear()
# Rotation
rotated_vertices = [rotateX(rotateY(rotateZ(v, angleZ), angleY), angleX) for v in vertices]
projected_vertices = [project(v) for v in rotated_vertices]
# Calculate the avg Z value
face_depths = []
for i, face in enumerate(faces):
z_sum = sum(rotated_vertices[vertex][2] for vertex in face)
face_depths.append((z_sum / len(face), i))
# Sort depth
face_depths.sort(reverse=True)
# Draw faces
for depth, i in face_depths:
face = faces[i]
t.penup()
t.goto(projected_vertices[face[0]][0], projected_vertices[face[0]][1])
t.pendown()
t.begin_fill()
t.color(colors[i % len(colors)])
for vertex in face:
t.goto(projected_vertices[vertex][0], projected_vertices[vertex][1])
t.goto(projected_vertices[face[0]][0], projected_vertices[face[0]][1])
t.end_fill()
screen.update()
# rotation angles
angleX = 0
angleY = 0
angleZ = 0
# Animation loop
def animate():
global angleX, angleY, angleZ
angleX += 2
angleY += 3
angleZ += 1
draw_polyhedron()
screen.ontimer(animate, 50)
# Initialize animation
screen.tracer(0)
animate()
screen.mainloop()
</code>
<code>import turtle import math # Setup screen = turtle.Screen() screen.bgcolor("light blue") # Set background screen.title("Spinning Diamond") t = turtle.Turtle() t.speed(0) t.hideturtle() # vertices vertices = [ [0, 0, 150], # Top vertex [math.cos(2 * math.pi / 5) * 100, math.sin(2 * math.pi / 5) * 100, 50], [math.cos(4 * math.pi / 5) * 100, math.sin(4 * math.pi / 5) * 100, 50], [math.cos(6 * math.pi / 5) * 100, math.sin(6 * math.pi / 5) * 100, 50], [math.cos(8 * math.pi / 5) * 100, math.sin(8 * math.pi / 5) * 100, 50], [math.cos(10 * math.pi / 5) * 100, math.sin(10 * math.pi / 5) * 100, 50], [math.cos(2 * math.pi / 5) * 100, math.sin(2 * math.pi / 5) * 100, -50], [math.cos(4 * math.pi / 5) * 100, math.sin(4 * math.pi / 5) * 100, -50], [math.cos(6 * math.pi / 5) * 100, math.sin(6 * math.pi / 5) * 100, -50], [math.cos(8 * math.pi / 5) * 100, math.sin(8 * math.pi / 5) * 100, -50], [math.cos(10 * math.pi / 5) * 100, math.sin(10 * math.pi / 5) * 100, -50], [0, 0, -150] # Bottom vertex ] faces = [ [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1], [6, 7, 11], [7, 8, 11], [8, 9, 11], [9, 10, 11], [10, 6, 11], [1, 2, 7, 6], [2, 3, 8, 7], [3, 4, 9, 8], [4, 5, 10, 9], [5, 1, 6, 10] ] # Define colors colors = [ "red", "green", "blue", "yellow", "cyan", "magenta", "orange", "purple", "lime", "pink", "brown", "gray", "violet", "navy", "gold" ] # Rotate around X-axis def rotateX(point, angle): rad = math.radians(angle) cosA = math.cos(rad) sinA = math.sin(rad) y = point[1] * cosA - point[2] * sinA z = point[1] * sinA + point[2] * cosA return [point[0], y, z] # Rotate around Y-axis def rotateY(point, angle): rad = math.radians(angle) cosA = math.cos(rad) sinA = math.sin(rad) x = point[0] * cosA + point[2] * sinA z = -point[0] * sinA + point[2] * cosA return [x, point[1], z] # Rotate around Z-axis def rotateZ(point, angle): rad = math.radians(angle) cosA = math.cos(rad) sinA = math.sin(rad) x = point[0] * cosA - point[1] * sinA y = point[0] * sinA + point[1] * cosA return [x, y, point[2]] def project(point): distance = 300 factor = distance / (distance - point[2]) x = point[0] * factor y = point[1] * factor return [x, y] # Draw Shape def draw_polyhedron(): t.clear() # Rotation rotated_vertices = [rotateX(rotateY(rotateZ(v, angleZ), angleY), angleX) for v in vertices] projected_vertices = [project(v) for v in rotated_vertices] # Calculate the avg Z value face_depths = [] for i, face in enumerate(faces): z_sum = sum(rotated_vertices[vertex][2] for vertex in face) face_depths.append((z_sum / len(face), i)) # Sort depth face_depths.sort(reverse=True) # Draw faces for depth, i in face_depths: face = faces[i] t.penup() t.goto(projected_vertices[face[0]][0], projected_vertices[face[0]][1]) t.pendown() t.begin_fill() t.color(colors[i % len(colors)]) for vertex in face: t.goto(projected_vertices[vertex][0], projected_vertices[vertex][1]) t.goto(projected_vertices[face[0]][0], projected_vertices[face[0]][1]) t.end_fill() screen.update() # rotation angles angleX = 0 angleY = 0 angleZ = 0 # Animation loop def animate(): global angleX, angleY, angleZ angleX += 2 angleY += 3 angleZ += 1 draw_polyhedron() screen.ontimer(animate, 50) # Initialize animation screen.tracer(0) animate() screen.mainloop() </code>
import turtle
import math

# Setup 
screen = turtle.Screen()
screen.bgcolor("light blue")  # Set background
screen.title("Spinning Diamond")
t = turtle.Turtle()
t.speed(0)
t.hideturtle()

# vertices 
vertices = [
    [0, 0, 150],  # Top vertex
    [math.cos(2 * math.pi / 5) * 100, math.sin(2 * math.pi / 5) * 100, 50],
    [math.cos(4 * math.pi / 5) * 100, math.sin(4 * math.pi / 5) * 100, 50],
    [math.cos(6 * math.pi / 5) * 100, math.sin(6 * math.pi / 5) * 100, 50],
    [math.cos(8 * math.pi / 5) * 100, math.sin(8 * math.pi / 5) * 100, 50],
    [math.cos(10 * math.pi / 5) * 100, math.sin(10 * math.pi / 5) * 100, 50],
    [math.cos(2 * math.pi / 5) * 100, math.sin(2 * math.pi / 5) * 100, -50],
    [math.cos(4 * math.pi / 5) * 100, math.sin(4 * math.pi / 5) * 100, -50],
    [math.cos(6 * math.pi / 5) * 100, math.sin(6 * math.pi / 5) * 100, -50],
    [math.cos(8 * math.pi / 5) * 100, math.sin(8 * math.pi / 5) * 100, -50],
    [math.cos(10 * math.pi / 5) * 100, math.sin(10 * math.pi / 5) * 100, -50],
    [0, 0, -150]  # Bottom vertex
]

faces = [
    [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 1],
    [6, 7, 11], [7, 8, 11], [8, 9, 11], [9, 10, 11], [10, 6, 11],
    [1, 2, 7, 6], [2, 3, 8, 7], [3, 4, 9, 8], [4, 5, 10, 9], [5, 1, 6, 10]
]

# Define colors 
colors = [
    "red", "green", "blue", "yellow", "cyan",
    "magenta", "orange", "purple", "lime", "pink",
    "brown", "gray", "violet", "navy", "gold"
]

# Rotate around X-axis
def rotateX(point, angle):
    rad = math.radians(angle)
    cosA = math.cos(rad)
    sinA = math.sin(rad)
    y = point[1] * cosA - point[2] * sinA
    z = point[1] * sinA + point[2] * cosA
    return [point[0], y, z]

# Rotate around Y-axis
def rotateY(point, angle):
    rad = math.radians(angle)
    cosA = math.cos(rad)
    sinA = math.sin(rad)
    x = point[0] * cosA + point[2] * sinA
    z = -point[0] * sinA + point[2] * cosA
    return [x, point[1], z]

# Rotate around Z-axis
def rotateZ(point, angle):
    rad = math.radians(angle)
    cosA = math.cos(rad)
    sinA = math.sin(rad)
    x = point[0] * cosA - point[1] * sinA
    y = point[0] * sinA + point[1] * cosA
    return [x, y, point[2]]

def project(point):
    distance = 300
    factor = distance / (distance - point[2])
    x = point[0] * factor
    y = point[1] * factor
    return [x, y]

# Draw Shape
def draw_polyhedron():
    t.clear()
    # Rotation
    rotated_vertices = [rotateX(rotateY(rotateZ(v, angleZ), angleY), angleX) for v in vertices]
    projected_vertices = [project(v) for v in rotated_vertices]

    # Calculate the avg Z value 
    face_depths = []
    for i, face in enumerate(faces):
        z_sum = sum(rotated_vertices[vertex][2] for vertex in face)
        face_depths.append((z_sum / len(face), i))

    # Sort depth
    face_depths.sort(reverse=True)

    # Draw faces 
    for depth, i in face_depths:
        face = faces[i]
        t.penup()
        t.goto(projected_vertices[face[0]][0], projected_vertices[face[0]][1])
        t.pendown()
        t.begin_fill()
        t.color(colors[i % len(colors)])
        for vertex in face:
            t.goto(projected_vertices[vertex][0], projected_vertices[vertex][1])
        t.goto(projected_vertices[face[0]][0], projected_vertices[face[0]][1])
        t.end_fill()

    screen.update()

# rotation angles
angleX = 0
angleY = 0
angleZ = 0

# Animation loop
def animate():
    global angleX, angleY, angleZ
    angleX += 2
    angleY += 3
    angleZ += 1
    draw_polyhedron()
    screen.ontimer(animate, 50)

# Initialize animation
screen.tracer(0)
animate()
screen.mainloop()

New contributor

Fadeh Baghomian is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật