Bhargav Rao
Bhargav Rao

Reputation: 52151

Program to print a circle of given diameter

I am trying to write a program to print a circle of given diameter in Berkeley logo. I get the input diameter from the user of the program and draw a circle accordingly. But I do not know of any method to display a circle given the diameter. All along I have been using,

repeat 36 [fd 10 rt 10]

to draw a circle. But it is not what I want. I tried using formulas for diameter, but it is not working. Can anybody please help?

Upvotes: -5

Views: 584

Answers (1)

user4239885
user4239885

Reputation:

You have to find the perimeter first, then divide it by the total number of rotations, then set that as the value of forward in your loop.

E.g.

make "d 100
make "p 3.141592654*:d
make "i :p/36
repeat 36[fd :i rt 10]

you can have all of them in a single statement as

repeat 36[fd 3.141592654*:d/36 rt 10]

where d is the accepted value of the diameter

Upvotes: 2

Related Questions