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 a neat pattern called a fractal.

A fractal is lots of tiny versions of pictures put together to make one big picture.

Technically, you could keep zooming in forever to get smaller and smaller versions but this example will only go down a few layers.

Artists use computers to draw cool fractals like the one you see here.

You can use a fractal to decorate your card.

In this add-on, you'll build a famous fractal called a Sierpinski triangle which is a triangle made up of smaller triangles.

First, program scratch to draw.

To do this, make sure the pen is down by dragging out the pen down block into the scripts area.

Next, make the sprite draw a triangle.

To begin, you'll need to make one big triangle.

To draw a triangle, the sprite needs to move 10 steps, turn 120 degrees, move 10 steps, turn 120 degrees, then move 10 steps and turn 120 degrees again.

Wait!

That is doing the same thing three times!

Instead of repeating those steps over and over add a repeat block with go forward, turn 120 degrees, and the number three.

This will create the outer most edges and angles of your Sierpinski triangle.

So enter a larger number than 10 in the move block.

Use one that can be divided by two a lot of times like 160.

Test!

Click on the code!

The sprite should draw a triangle.

It does!

Great.

But in order for this to be a fractal, the triangle must be made up of other smaller triangles, not just one on its own.

Start by making a triangle half the size of this one.

Just like when you created the big triangle, add a repeat block and make the number of repeats three.

Again, just like for the big triangle, turn 120 degrees.

To draw, use the move block.

The distance moved however, will be different.

To make a triangle half the size of the big one, move half as far, or 80 steps.

Write 80 in this new move block.

Test the code.

Great!

It makes a triangle that is half as wide and tall as the first.

To make a Sierpinski triangle though, the entire large triangle needs to be built from smaller triangles.

To make that happen, put the code that draws the small triangle inside the repeat block above the code that creates the single, large triangle.

Click on the code.

The large triangle is now made up of three triangles half its size.

Remember that a fractal looks the same no matter how far you zoom in.

To make this design into a fractal, make these three triangles out of three triangles half their size.

To do this, again drag out the repeat, move and turn blocks.

This time make the value in the move block half of 80, 40 and put it in side the second repeat loop.

Test the code.

Great!

Each of the three small triangles are now made up of even smaller triangles.

Repeat these triangle-making steps until you have a fractal pattern you like.

You may find it easier to duplicate the code for an individual triangle by clicking on it, then adjusting the number in the move block.

When you are finished, consider tinkering with the code to change elements of the fractal design.

For example, use the go to block to change the placement of the design.

Or use the point in direction block to change its direction.

Use the set pen color to block to make color changes and use the clear block to remove old drawings.

Maybe even make the direction or starting location random and/or build more than one Sierpinski triangle.

Use your creativity and have fun.

Be sure to add an event to tell the sprite when to start.

Now it's your turn.

Use the pen down block to make Scratch draw.

Use the repeat, move, and turn blocks to create a triangle, program another triangle half the size of the original one.

Place it inside the repeat loop that creates the large triangle to make a triangle out of triangles.

Keep doing this until you create a fractal design you like.

Tinker with different elements of the design to make it your own.

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