Last active
May 1, 2024 17:21
-
-
Save pgram1/3aa6d990475ed7a9c69de4894faa0703 to your computer and use it in GitHub Desktop.
Triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_triangle(height): | |
ellipse_width = height // 2 | |
ellipse_radius_x = ellipse_width // 2 | |
ellipse_radius_y = height // 4 | |
eye_width = ellipse_width // 2 | |
eye_radius_x = eye_width // 2 | |
eye_radius_y = eye_width // 4 | |
for i in range(height): | |
line = '' | |
for j in range(2 * i + 1): | |
x = j - (2 * i + 1) // 2 | |
y = i - height // 2 | |
if x * x / (ellipse_radius_x * ellipse_radius_x) + y * y / (ellipse_radius_y * ellipse_radius_y) <= 1: | |
if x * x / (eye_radius_x * eye_radius_x) + y * y / (eye_radius_y * eye_radius_y) <= 1: | |
line += '●' | |
else: | |
line += ' ' | |
else: | |
line += '▲' | |
print(' ' * (height - i - 1) + line) | |
# Call the function | |
generate_triangle(51) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment