Mathematics Scratch Arts
Easy
45 mins
385 points
What you need:
  • Computer/laptop

Pattern Creator

Create some cool patterns by coding the pen tool and use some variables to change the pattern.

Unfortunately we had a technical issue with the video for this Code Along and it is not available.
This message will be visible to everyone. Send

    This code along has finished! ⌚

    You can watch it back by playing the video!

    The code along is open for everyone to join in but if you would like to earn the points and badges please join our club!

    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.



    6 - Use the steps and degrees

    We will start the steps variable at 0 and then add 1 to it in the repeat until  block.

    Add a set [steps] to 0 block underneath the when clicked block.

    Drag the steps block into the move 5 steps block.

    Drag the degrees block into the turn 5 degrees block.

    Add a change [steps] by 1 block inside the repeat until block.

    when green flag clicked set [steps v] to (0) // add this block go to x (0) y (0) hide pen up erase all set pen color to [#3438df] pen down repeat until < touching [edge v] ? > move (steps) steps // add the steps variable turn cw (degrees) degrees // add the degrees variable change [steps v] by (1) // add this block end

    Click on the green flag and your code should draw a straight line.


    7 - Change the degrees

    Move the degrees slider to set it to 20 and then click the green flag. You'll notice that is draws a spiral.

    Try moving the slider to different values and clicking the green flag to see what patterns it makes.



    8 - Add some colour

    Add a change pen [color] by 10 block inside the repeat until block to change the color of your pattern as it's being drawn.

    when green flag clicked set [steps v] to (0) go to x (0) y (0) hide pen up erase all set pen color to [#3438df] pen down repeat until < touching [edge v] ? > move (steps) steps turn cw (degrees) degrees change [steps v] by (1) change pen [color v] by (10)// add this block end

    Click on the green flag and your code should now draw a multicolored pattern.


    9 - Change the pen size

    Finally add a set pen size to 1 block underneath the pen down block and drag the size block inside it. Then try changing the size variable using the slider and running the code.

    when green flag clicked set [steps v] to (0) go to x (0) y (0) hide pen up erase all set pen color to [#3438df] pen down set pen size to (size) // add this block repeat until < touching [edge v] ? > move (steps) steps turn cw (degrees) degrees change [steps v] by (1) change pen [color v] by (10) end

    Click on the green flag and your code should now draw in a different pen size.



    10 - Play around

    Try playing around with different degrees and pen sizes to create different patterns.


    Join our club 😃

    Create your profile, earn points & badges and learn how to code!

    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