Course Content
Rectangles and Ellipses

Let's look at how to draw rectangle and ellipse shapes. As you could have guessed, there are two new functions rectangle and ellipse.

s1 = rectangle()
s2 = ellipse()
show(s1, s2)

We could create a rectangle or an ellipse with different width and height by specifying the parameters w and h respectively.

s1 = rectangle(w=100, h=50)
s2 = ellipse(w=200, h=100)
show(s1, s2)

Both the rectangle and the ellipse are centered around the origin by default. Just like with the circle, we can specify the center of the shape by specifying parameters x and y.

s1 = rectangle(x=0, y=-50, w=150, h=100)
s2 = ellipse(x=0, y=50, w=150, h=100)
show(s1, s2)

Exercise 2.9: Draw a Square

Draw a square of length 200 using the rectangle function.


Exercise 2.10: Two Concentric Squares

Draw two concentric squares around the origin with length 200 and 100 respectively.


Exercise 2.11: Two Rectangles

Draw two rectangles as shown in the figure. Both the rectangles have sides as 100 and 200.


Exercise 2.12: Two Ellipses

Draw two ellipses as shown in the figure.


Exercise 2.13: The Eye

Draw an eye as shown in the figure. Can you guess what are the dimensions?


Questions
Regarding 2.13
Ak _00
1 year ago
Post
Dismiss

What is the input for eye in question number 2.13 ?

DL Dheeraj Latish
1 year ago
Post
Dismiss

s1 = ellipse(w=200, h=100) c1=circle(r=50)

MJ Meenakshi Jayakumar
1 year ago
Post
Dismiss

s1 = ellipse(w=200, h=100) s2 = circle(x=0,y=0, r=50)

show(s1,s2)

Want to discuss?
Post it here, our mentors will help you out.