Coding Ireland STEM Report 2024 Have Your Say
Mathematics Scratch Arts
Intermediate
45 mins
160 points
What you need:
  • Computer/laptop

Pattern Creator

Create some cool patterns by coding the pen tool and some variables.

1 - Create a new Scratch project

Go to the Scratch website, create a new project and delete the cat sprite.

scratch.mit.edu/projects/editor

2 - Add the Ball sprite

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


3 - Add the Pen Extension

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


4 - Draw a circle

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.


5 - Create some variables

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:

  1. steps - this will be how far it moves
  2. degrees - this will be how much it turns
  3. size - this will be the size of then pen

Hide the steps variable by unchecking it in the toolbox and make the degrees and size display as sliders in the stage area.



Join our club 😃

To view the remaining 5 steps and access hundreds of other coding projects please login or create an account.

Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more