Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more.

Transcript

This add on will show you how to make your very own block.

In this club, you have used blocks that are already included in Scratch.

You can also design your own block.

This video will show you how to make a block that draws spirals, but you can make blocks do all sorts of cool things.

Watch this video to learn how to make your own block.

Then, try it out.

First, write the code to draw a spiral.

A spiral is a bit difficult to draw so break it down into steps.

Start by drawing a circle, then modify it to be a spiral.

First, drag out the pen down block, then add a move 10 steps block and a turn 30 degrees block.

Put the whole stack inside a repeat 30 block.

Now, click the block stack to see the pen draw a circle.

To modify the circle code to make it a spiral, the move 10 steps needs to be altered so that the number 10 changes over time.

To make that possible, use a variable.

Create a variable called distance.

Drag out the distance variable and put it inside the move 10 steps block.

Also, drag out the change distance by block and place it inside the repeat loop as well.

Click the block stack.

Now the pen draws a spiral.

Add a set distance to zero block at the beginning of the block stack to reset the variable each time the spiral is drawn.

If you want to make lots of spirals, this code can get long and hard to read.

It would be much easier if you could just tell Scratch to make a spiral the way you tell it to make a sprite stamp or say something.

Luckily, Scratch lets you make your very own block.

From the more blocks section, drag out a new block.

Click make a block and name it something that relates to what you want it to do.

This one is called draw a spiral.

A new block should automatically appear in the scripts area.

Connect the block to the top of the spiral drawing code stack.

This lets Scratch know that when you use draw a spiral, you mean to execute this code.

Now you can use the draw a spiral block just like any other block.

For example, drag out your forever block, then place a draw a spiral block and a change pen color by 10 block inside the forever loop.

To make sure the spiral doesn't draw in between making spirals put a pen up block in the forever loop.

Make the sprite appear in random places with a go to x y block.

Put a pick random block in the bubble for x and another for y.

Make the x be from -240 to 240 and the y, from -180 to 180 to cover the whole screen.

Lastly, add a when flag clicked event.

Test it out.

It draws many spirals now moving around the screen and changing color as it goes.

Now it's your turn.

Try building your own block to make spirals, or to do any other task you want.

Refer to the code demonstrated in this video if you get stuck, or ask a neighbor for help with debugging.

Choose an Add-On

Party Time!

Make sprites spin and change colors.

Now You See Me...

Using "show" and "hide" make the sprites in your project appear and disappear.

Stage Lights

Change the background based on user input.

Random Appearances

Make art elements appear randomly.

Triangles All the Way Down

Create a fractal with many little triangles.

Spirals

Learn how to create spirals.

Instructions
  1. Choose a recipient for your card, such as a parent, friend, Guru, or Host.
  2. Craft and code a message for that person about CS First.
  3. Create art to enhance your card and show off what you've learned in this club.
Attributions
  • "Crowd down the street" by Guillaume (https://www.flickr.com/photos/guiguibu91/2889883615) -- Licensed by CC BY 2.0 (https://creativecommons.org/licenses/by/2.0/) -- Image scaled up, cropping edges
  • "Greetingcards" by Sotakeit (https://commons.wikimedia.org/wiki/File:Greetingscards.jpg) -- Licensed by Creative Commons Attribution 3.0 Unported (https://creativecommons.org/licenses/by/3.0/legalcode) -- Image scaled up, cropping edges