Please update your browser
Your browser version is not supported by this site. CS First may not work properly.
In this video,
you will create your own paint program
and make the scanner sprite invert the colors.
To do this, you will keep the scanner sprite's functionality
and add a new script.
First, create a blank backdrop.
To do that, click on the stage and the backdrops tab.
Click on paint new backdrop
and use the paint bucket tool to make it black.
Now, add a new sprite to the project.
This project uses the star, but you can use any sprite.
First, create a stack of code that allows your sprite
to follow the mouse pointer and draw.
Start by getting the sprite to follow your mouse.
In the paint with Tara project,
you used a go to mouse pointer block
from the motion menu and a forever loop from control.
Click on the code to see if the sprite follows your mouse.
Because you are already adding
to the scanner sprite program,
add a, when sprite clicked event, to the top of the stack.
Test it by clicking on the sprite.
To make your sprite begin drawing, go to the pen menu
and pull out the pen down block.
Put it in the forever loop.
When you click the code,
the sprite should now constantly draw.
To make the scanner sprite program run properly,
the sprite should draw in a color other than black.
Add a set pen color to block in the stack
and make the color something other than black or white.
This example uses green.
Test it by drawing something,
then click on the green flag,
notice that when you click the green flag,
your drawing disappears.
To fix this, click on the scanner sprite
and separate the, when flag clicked,
and clear blocks, from the stack.
Add a key press event to the top of the stack,
and change the key to one.
The code now clears when the flag is clicked,
but runs only when you press the correct key.
Test it again and the scanner sprite changes the drawing.
But, it still isn't perfect.
For one thing, the line you're drawing is too thin
to be scanned easily by the scanner sprite.
To change the width of your pen,
add a, set pen size to, block to the stack.
Change the value to something like five.
Try it out.
You also can't control when to draw with the pen
and when not to.
Fix this using the pen up block and an if then block.
Pull out an if block and put it into the forever loop.
Go to the sensing menu and add a mouse down block.
This will ensure that the pen draws
only when the mouse is pressed.
Move the, pen down, set pen color to
and set pen size to blocks inside the if block.
Finally, add the, pen up block, before the if statement
to make sure the pen draws
only when the mouse pointer is pressed.
Test this by clicking on your sprite and drawing a picture.
When you press the mouse button down, it doesn't draw.
That's because you pick up the sprite instead.
Fix this bug by making your sprite hide.
Add a hide block under the when sprite clicked block.
Now test it.
Though the sprite has disappeared,
you can draw with the mouse pointer.
Finally, add a show block and a when flag clicked block.
This makes the sprite appear
each time you start the program.
Test out all the features by pressing the green flag.
If it lags when you draw, turn off turbo mode.
Press the one key to invert the image.
Now it's your turn.
Add a new sprite and a black backdrop.
Make the sprite constantly move toward the mouse pointer
and start when the use clicks it.
Make the pen draw and stop drawing
at the correct times using the pen tools
and an if statement.