(c) 2021 George Gadanidis

Get the task as a PDF: https://learnx.ca/wp-content/uploads/2021/04/primes-scratch-task-1.pdf

Estimate the value of Pi using the number of random darts that fall in the pink circle and in the blue square, as illustrated in the image below.

Start by coding these components:

- Draw a 200 x 200 pixels square, in the centre of the Scratch Stage.
- Draw the largest possible circle in the square
- Throw 1000 darts at random points on the stage
- Stamp the points pink if they fall in the circle, blue in the square beyond the circle, and yellow everywhere else
- Count the different colours of points
- Estimate the value of Pi

Create a poster presentation of what you did, what you learned, and what else you would like to know.

TEACHERNOTE:A solution to the Task: https://scratch.mit.edu/projects/510595373/editor

## 1. CONTEXT

#### A. CURRICULUM CONNECTIONS

**Math topics**: circle properties, Pythagorean Theorem, inequalities, experimental probability**Coding topics (Scratch)**: using the Pen tool to draw, code blocks (sub-programs), random screen locations, conditional structures

**B. In search of Pi**

How can we write code to dynamically model the square-circle relationship and use the relationship to estimate Pi?

Before we start coding, we need to understand the math relationship that gives us Pi. Here is one way:

We have a pink circle, with radius **r**, that just fits inside a blue square. That is, the pink circle is the biggest circle that can fit inside the square.

**A.** What is the area of the circle? ___________

**B. **What is the area of the square? ___________

**C.** Complete the fraction below, and simply expressions as much as possible:

**2. CONNECTING THE DOTS**

#### A. VARIABLES

Discuss in your team:

Suppose we have these 3 variables we can use to count the number of pink dots and the number of blue dots, and then estimate the value of Pi.

**A.** How may we use these variables, and the result from 1.C, to estimate the value of Pi?

**B.** Write an algebraic expression using these variables to estimate the value of Pi.

**3. DRAW A SQUARE WITH SCRATCH **

**A. Add the Pen extension to Scratch**

Click on the icon shown below to access Scratch extensions.

Select the Pen extension.

The Pen extension will allow you to draw path and to also stamp on the Stage.

**B. Add a grid backdrop to the Stage**

Click on the icon shown below to see the backdrops available.

Select the Xy-grid-20px backdrop.

Each square on the gris is 20 pixels wide and high.

Notice the x and y coordinate axes drawn faintly on the grid.

This grid will serve as a guide, later, when we draw the square and the circle.

**C. SELECT the Ball sprite**

Delete the Cat sprite.

Click on the icon shown below and choose the Ball sprite.

Change the size of the Ball sprite to 20.

**D. Edit sprite costumes **

Select the Costumes tab and rename the Ball costumes simply by their colours: yellow, blue, pink, green and purple, as shown on the right.

This will help us later, as we switch costumes of the Ball sprite depending on which coordinates the random darts land.

**E. Create a new Scratch block **

The code below draws the 200 pixels by 200 pixels square shown on the right.

To define the “draw square” block, go to

and then click on

## 4. DRAW A CIRCLE

Similarly (see #1 above), define a “draw circle” block, that draws the biggest circle that fits in the square.

The circle should be pink in colour.

**5. DEDINE & INITIALIZE VARIABLES**

We’ll need the following variables:

**x**and**y**, to represent coordinates where darts land on the Stage**pink**and**blue**, to count how many darts land in the circle (pink) and how many land in the square outside if the circle (blue)**darts**to count the total number of darts thrown**pi**to store the value of Pi that we calculate

Set initial values for blue, pink and darts

**6. THROW 1000 RANDOM DARTS**

The code below selects 1000 random **(x, y)** positions for the darts.

**7. DEFINE A NEW CODE BLOCK**

Define this new code block. Its code is shown below.

How will you know if the dart lands outside of the square?

How will you know if the dart lands in the square but not the circle?

How will you know if the dart lands in the circle?

Complete the if/then conditional statements.