drawrect.py

Created by ews31415

Created on May 31, 2024

333 Bytes

Draw a rectangle given its horizontal length (h) and vertical length (v). If the horizontal and vertical lengths are equal, a square is drawn. The rectangle is centered at (0, 0). 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 a rectangle\nusing pyplot")
h=eval(input("horiz. length? "))
v=eval(input("vert. length? "))

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

# set points
xl=[-h/2,h/2,h/2,-h/2,-h/2]
yl=[v/2,v/2,-v/2,-v/2,v/2]

# color
c='green'

# draw rectangle
plot(xl,yl,c)
show()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.