drawtrieq.py

Created by ews31415

Created on June 01, 2024

299 Bytes

Draws an equilateral (60-60-60) triangle. Enter the length of the side (s). The base is set on the x-axis. The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64.


from math import *
from matplotlib.pyplot import *

print("Draw an equilateral triangle\nusing pyplot")
s=eval(input("side length? "))

# set axis
axis((-64,64,-44,44))

# set points
t=s*sqrt(3)/2
xl=[-s/2,s/2,0,-s/2]
yl=[0,0,t,0]

# draw the triangle
c='brown'
plot(xl,yl,c)
show()