Shelly is a programming language which you can use to draw figures. Drawing is done by issuing instructions to a turtle. The turtle draws lines and shapes as it moves, using various colors and styles. It might look complex at first however it doesn’t take long to get used to the syntax and is quite easy.
There are a few keywords in Shelly which you need to be familiar with to draw figures.
First are the keywords which helps in drawing the lines.
- fw – Move forward the given number of steps
- bk – Move backward the given number of steps
- right – Will change the direction by 90 degrees to the right. Any lines or shapes drawn afterwards will now have a different direction
- left – Will change the direction by 90 degrees to the left. Any lines or shapes drawn afterwards will now have a different direction.
- up – It doesn’t draw while moving. This way, you can move to a different section of the canvas without leaving a trail.
- down – It starts drawing while moving. In combination with up, this can be used to temporarily move around without drawing.
- pen – Using the pen instruction you can change the color and style of the pen, with which the turtle draws lines and shapes.
- fill – Using the fill instruction you can change the color and opacity of the fill.
- goto – Goto allows to jump to the given x y coordinates.
Here are a few keywords for drawing shapes.
- circle – Draws a circle with the given radius.
- ellipse – Draws an ellipse with the given x-radius and y-radius.
- rectangle – Draws a rectangle with the given sides.
- square – Draws a square with the given side
- triangle – Draws a triangle with the give side.
- text – Prints the given text at the current location of the turtle. The text will be rotated the same as the turtle. The text needs to be surrounded with double quotes (“…”).
Examples in Shelly :
#1. Drawing a concentric square
pen color:yellow let side = 15 repeat 20 (i. fw side*i right 90 )
#2. For a hexagonal structure, change the right angle to 45 degrees
pen color:yellow let side = 5 repeat 45 (i. fw side*i right 45 )
#3. Drawing concentric circles
pen color:yellow repeat 10 (i. let side = 30 circle side*i )
So, that’s it for this tutorial. Stay tuned for more.