Create some cool patterns by coding the pen tool and some variables.
Go to the Scratch website, create a new project and delete the cat sprite.
scratch.mit.edu/projects/editor
Go to the Scratch website using the link below and click on the 'Create' link in the blue bar at the top.
By default, each new project starts with the cat sprite already added. To delete the cat click on the x in the blue circle beside the cat in the sprite list.
We are going to use the Pen blocks to create patterns but first we'll need to add a sprite that will do the drawing. It doesn't really matter which sprite we use as we are going to hide it.
Add the Ball sprite from the sprite library and then give it the following code.
when green flag clicked
go to x (0) y (0) // we want to start it in the center
hide
To add a sprite from the sprite library follow these steps:
You can use search box or the filter links (Animals, People, Fantasy etc) to locate your sprite.
To draw the patterns we will be using the Pen blocks so add the Pen Extension to your project.
Once you've added the Pen Extension add the following new code blocks to the Ball sprite underneath the hide block.
when green flag clicked
go to x (0) y (0)
hide // add new code under here
pen up // start with the pen up
erase all // erase drawings from the last time
set pen color to [#3438df] // choose a color
pen down // put the pen down
Scratch Extensions make it possible to connect Scratch projects with external hardware (such as LEGO WeDo or micro:bit), sources of information on the web (such as Google Translate and Amazon Text to Speech), or blocks allowing for more advanced functionality.
When an extension is enabled, its blocks appear in a location with the same name as the extension.
To load an extension, click the icon in the bottom-left hand corner of the screen and select an extension.
Now let's add some code to move the sprite. As the we set the pen to be down, moving the sprite will make the the pen draw.
We will make the sprite move and turn and by putting these instructions inside a loop block it will make the sprite go in a circle.
Add the following code to the Ball sprite underneath the pen down block to draw a circle.
when green flag clicked
go to x (0) y (0)
hide
pen up
erase all
set pen color to [#3438df]
pen down // add new code under here
repeat until < touching [edge v] ? >
move (5) steps
turn cw (5) degrees
end
Click on the green flag and your code should draw a circle.
Now let's add some variability ("variability" means change) so that we can draw some more complex shapes and patterns.
Create the following three variables:
Hide the steps variable by unchecking it in the toolbox and make the degrees and size display as sliders in the stage area.
In the Variables palette, create a new variable by clicking the 'Make a Variable' button.
Once you click this button a box will appear asking what you want to call your variable. Give it a name that reminds you what you will be using it for. For example, if you wanted to keep track of your score in a game, you would create a variable called 'score'.