The Joy of Programming
Drawing Circles

In this lesson, we'll learn how to write programs to draw circles on the canvas.

Simple Circle

We'll start with drawing a circle. This involves two steps, creating a circle and showing it.

c = circle()
show(c)

The first line creates a circle shape and the secone line shows it.

Just like the print function is used to display numbers and strings, the show function is used to display shapes.

Controlling the Size

The size of the circle is controlled by its radius. By default, the radius of the circle will be 100, but we can specify a different value for the radius. The is done by setting the parameter r.

c = circle(r=50)
show(c)

Try making the circle bigger by changing the value of parameter r.

!!! note 'Named and positional arguments'

You may have noticed that we are using the `circle` and
the `show` functions very differently.

We are calling the `show` function as `show(c)`, but the `circle`
function as `circle(r=50)` and not as `circle(50)`.

In Python, it is possible to pass arguments by name (like r=50, x=10 etc)
and by position (like in `print(1, 2, 3)`).

It is too early for us to get into those details. For now, just understand
that both these ways are acceptible.

More Circles

We can also create more than one circle. The following example draws two conentric circles with radius 50 and 100.

c1 = circle(r=50)
show(c1)

c2 = circle(r=100)
show(c2)

Just like print, the show function also supports taking multiple arguments and we can use that to show multiple shapes at once.

c1 = circle(r=50)
c2 = circle(r=100)
show(c1, c2)

Exercise 2.1: Three Concentric Circles

Draw three concentric circles with radius 50, 100 and 150 respectively.


Questions
VIGHNESH 321
3 years ago
Post
Dismiss
How to draw rectangle in vertical?
How to draw rectangle in vertical?
VIGHNESH 321
3 years ago
Post
Dismiss
Cmd+
Cmd+
MJ Meenakshi Jayakumar
3 years ago
Post
Dismiss
Try changing the values of the parameters (height and width) Example : c = rectangle(w=100,h=200) show(c)
Try changing the values of the parameters (height and width) Example : c = rectangle(w=100,h=200) show(c)
Want to discuss?
Post it here, our mentors will help you out.
circle function
Yadhu Krishnan
3 years ago
Post
Dismiss
Why these circle function is not working in python IDLE(python 3.10)?
Why these circle function is not working in python IDLE(python 3.10)?
MJ Meenakshi Jayakumar
3 years ago
Post
Dismiss
That could be because these exercises are done using the library "Joy" which is already included in the course environment. To do the same on Python IDLE , you might have to create a new function.
That could be because these exercises are done using the library "Joy" which is already included in the course environment. To do the same on Python IDLE , you might have to create a new function.
Want to discuss?
Post it here, our mentors will help you out.
Comment 1
Yeldos Nurymov
3 years ago
Post
Dismiss
Good comment
Good comment
PR Pratheek Rao K B
3 years ago
Post
Dismiss
Very Informative Class.
Very Informative Class.
TV Theertha Vinod
3 years ago
Post
Dismiss
Good class
Good class
Want to discuss?
Post it here, our mentors will help you out.