Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make a script that draws circles?
- goodpersonsowow
-
Scratcher
100+ posts
How to make a script that draws circles?
I have a project called Paint (which used to be called Drawing). I added line mode, now it's time for circle mode. How do you implement circle mode in scratch? The link is here.
- awesome-llama
-
Scratcher
1000+ posts
How to make a script that draws circles?
It depends on how you want the user to draw circles. Here are some example ways they could interact…
Though regardless of the option you choose, drawing the circle itself can be done by making lots of little steps. They will be straight lines but with enough steps the circle will look fine. With this method it means you can easily draw other regular polygons too. A circle could be thought of as just a polygon with infinite sides.
Trigonometry is what I recommend to draw the circle. Set an angle and go to it based on the sine and cosine of that angle. Repeatedly increase the angle and go to the new position. Once you've reached 360 degrees, you've made a circle.
Here's a script you could follow to get started…
- Click in the circle's center and drag outward to set the radius.
- Assume the circle is mapped to a square and let the user draw the corners of the square would would in turn define the shape of the circle (like how scratch's costume editor works).
- Click where the circle should touch and drag to another point where the opposite side of the circle should touch.
Though regardless of the option you choose, drawing the circle itself can be done by making lots of little steps. They will be straight lines but with enough steps the circle will look fine. With this method it means you can easily draw other regular polygons too. A circle could be thought of as just a polygon with infinite sides.
Trigonometry is what I recommend to draw the circle. Set an angle and go to it based on the sine and cosine of that angle. Repeatedly increase the angle and go to the new position. Once you've reached 360 degrees, you've made a circle.
Here's a script you could follow to get started…
define draw circle at (x)(y) with radius (radius) and steps (steps)
set [angle v] to [0]
repeat ((steps) + (1))
go to x: ((x) + ((radius) * ([sin v] of (angle )))) y: ((y) + ((radius) * ([cos v] of (angle ))))
pen down
change [angle v] by ((360) / (steps))
end
pen up
when green flag clicked
erase all::pen
draw circle at (25)(25) with radius (60) and steps (24)
Last edited by awesome-llama (Jan. 2, 2023 14:02:19)
- goodpersonsowow
-
Scratcher
100+ posts
How to make a script that draws circles?
It depends on how you want the user to draw circles. Here are some example ways they could interact…How can I fill the circle in?
- Click in the circle's center and drag outward to set the radius.
- Assume the circle is mapped to a square and let the user draw the corners of the square would would in turn define the shape of the circle (like how scratch's costume editor works).
- Click where the circle should touch and drag to another point where the opposite side of the circle should touch.
Though regardless of the option you choose, drawing the circle itself can be done by making lots of little steps. They will be straight lines but with enough steps the circle will look fine. With this method it means you can easily draw other regular polygons too. A circle could be thought of as just a polygon with infinite sides.
Trigonometry is what I recommend to draw the circle. Set an angle and go to it based on the sine and cosine of that angle. Repeatedly increase the angle and go to the new position. Once you've reached 360 degrees, you've made a circle.
Here's a script you could follow to get started…define draw circle at (x)(y) with radius (radius) and steps (steps)
set [angle v] to [0]
repeat ((steps) + (1))
go to x: ((x) + ((radius) * ([sin v] of (angle )))) y: ((y) + ((radius) * ([cos v] of (angle ))))
pen down
change [angle v] by ((360) / (steps))
end
pen up
when green flag clicked
erase all::pen
draw circle at (25)(25) with radius (60) and steps (24)
- awesome-llama
-
Scratcher
1000+ posts
How to make a script that draws circles?
How can I fill the circle in?The pen draws with circles.
Go to the center, set size to size of the circle, then pen down, pen up.
Last edited by awesome-llama (Jan. 2, 2023 15:05:41)
- goodpersonsowow
-
Scratcher
100+ posts
How to make a script that draws circles?
I'm ready for the next step.
- Discussion Forums
- » Help with Scripts
-
» How to make a script that draws circles?

