S
ScratchLabBeta

Curriculum

Lesson 2: Painting Game with Pen

Overview

In this lesson we’ll be using a scratch extension called Pen and make a fun drawing game.

If you want to take a look at the end result, here it is: https://scratch.mit.edu/projects/1286628644/

Installing Pen

In scratch there are an number of useful (or not so useful) extensions that you can use to enhance your projects. In this tutorial we’ll be using Pen, it helps us draw on the screen without overloading scratch, as it would be very difficult to achieve this otherwise. To install it, go to the purple icon on the bottom left of your screen and click on it. Then, select “Pen”. You will now see a new category pop up. Go there to see all the new blocks you can use.

The Forever Loop

First get a When Green Flag Clicked block (in the cat sprite). Then we’ll need a new kind of loop that you’ve probably not come across before, the Forever Loop. Find it in the control category and attach it to the hat block. We use this loop here because we don’t just want this to repeat 10, 20 or 30 times, we want it to go on until the user stops the project. This ensures that whatever we put into this loop will always be running.

Pen Blocks

Before the Forever Loop add a “erase all” block. We need this because we don’t want everything you’ve drawn previously to show up again when you run the project a second time. In the forever loop add a “stamp” block. It puts down a stationary cat everywhere where the cat moves. Your code should now look like this:

Basic game loopBasic game loop

Movement

If you haven’t noticed yet, although the stamping is working just fine, we aren’t moving the cat which makes all the stamped cats appear in the same spot. The most effective way to draw is to stamp the cat exactly where the mouse is. Go to the motion category and find the “go to: (random position block)”. Change the “random position” to “mouse pointer”, insert it into the forever loop and now the project should work.

Erase all when Space pressed

If you experiment around, you will quickly run into a problem; there are too many cats on screen. Luckily there is a simple way to fix that. Go to the control category and select an “if …. then” block. Then go to the sensing category and get a “space key pressed?” block. Insert it into the if then block’s predicate (the edgy space in the block itself). After that, just add an erase all into the if statement. Your final code should look like this:

Final scriptFinal script

Done? Well, not Quite

Although you could just say that the cat moves around, and paints copies of itself on the screen, there are still many ways in which you can possibly improve this project. Some of them are:

  • Adding a color effect to make it seem less boring (which is what you can see in my project)
  • Making the cat change costume when a certain key is pressed so you can draw different shapes
  • Your own ideas

With that said, see you in the next one;)