# Learning Geometry With Scratch – Basic 2D Shapes

This post is also available in: العربية (Arabic)

## What is Scratch?

Scratch is a block-based visual programming language and website targeted primarily at children 8-16 as an educational tool for coding. Users of the site can create projects on the web using a block-like interface. The service is developed by the MIT Media Lab. It’s available in 70+ languages and is used in most parts of the world.

Scratch takes its name from a technique used by disk jockeys called “scratching”, where vinyl records are clipped together and manipulated on a turntable to produce different sound effects and music. Like scratching, the website lets users mix together different media (including graphics, sound, and other programs) in creative ways by creating and remixing projects, like video games, animations, and simulations.

## How to Draw in Scratch?

This article “Learning Geometry With Scratch – Basic 2D Shapes” is about drawing geometrical figures using Scratch block codes.

To facilitate drawing in Scratch, a feature called “pen” is available. It allows a sprite to draw shapes, plot coloured pixels, and so forth on the screen. The “pen” is available as a Pen Extension in the Extension Menu.

The Pen Extension allows sprites to control their pens onto the stage to draw images and figures. Pen blocks can also be used to make Games and Simulations, as well as other things. There are 9 blocks in Pen.

## X and Y Coordinates

The position of a sprite or any object on the stage is denoted by x (horizontal → or ←) and y (vertical ↑ or ↓) coordinates. When you place a character on the stage, the sprite pane shows x and y coordinates. They tell where the sprite is on the stage. If you drag the sprite, the numbers change because the position is now different.

## Using X and Y Coordinates On the Scratch Stage

You cannot see it – but the Scratch stage is divided into four parts. This is done using two number lines. One horizontal line and the other vertical line. The horizontal line is called the X-axis and the vertical line is called the Y-axis.

The X number line goes from left to right. It tells where a sprite is on the stage horizontally.

The Y number line goes from top to bottom. It tells where a sprite is on the stage vertically.

The center of the stage is where the two number lines meet.

## What Do the x and y Values Tell?

Each part of the stage is made up of dots. Each dot has an x value and a y value that tell its location on the stage.

The x value tells you how many steps to move right or left from the centre point. If the number is positive, move right. If it is negative, move left.

The y value tells you how many steps to move up or down from the centre point. If the number is positive, move up. If it is negative, move down.

Observe the picture below. Where is the ‘red dot’ on the stage? First, count across to get the x value. Then count up or down to get the y value. Here, it is at x = 150 and y = 100.

Note that the X and Y lines divide the stage into 4 regions:

Top Right: All points in this region have both x and y values positive.

Top Left: All points in this region have negative x values and positive y values.

Bottom Left: All points in this region have both x and y values negative.

Bottom Right: All points in this region have positive x values and negative y values.

The centre of the stage has x = 0 and y = 0.

## Using Pen to Draw on Stage

Drawing in Scratch is like doing a dot-to-dot puzzle. To draw a picture, build a script that puts the pen down at the first dot. Then move the pen from one dot to the next. Once you are done with the drawing, lift the pen up.

## Drawing a Straight Line

Let’s first see how to draw a horizontal line. In the case of a horizontal line, the value y-coordinate of two endpoints remains the same, whereas the value of x-coordinates of two endpoints differs.

In the case of a vertical line, the value x-coordinate of two endpoints remains the same, whereas the value of y-coordinates of two endpoints differs.

You can also draw horizontal and vertical lines by using the ‘repeat’ and ‘move’ blocks.

A vertical line also can be drawn using the ‘repeat’ and ‘move’ blocks. Pointing the pencil 90 (in degrees) places the pencil (sprite) horizontally facing towards the right. Turning it 90 (in degrees, clockwise), positions the pencil in the vertical direction.

## Drawing a Square

A square is a plane figure, whose all sides are equal and the measure of each angle is 90 degrees.

Let’s try to draw the following square with coordinates as shown in the figure. It’s a square whose each side is 200 steps.

You can also draw a square using the ‘repeat’ and ‘move’ blocks. While drawing a square using a ‘move’ block remember that the side of each square is equal and the measure of each angle is 90 degrees.

## Drawing a Rectangle

A rectangle is a plane figure, whose opposite sides are equal and the measure of each angle is 90 degrees.

Let’s try to draw the following rectangle with coordinates as shown in the figure. It’s a rectangle whose one pair of opposite sides is 200 steps and the other pair of sides is 100 steps.

You can also draw a rectangle using the ‘repeat’ and ‘move’ blocks. While drawing a square using the ‘repeat’ and  ‘move’ blocks remember that the opposite sides of a square are equal and the measure of each angle is 90 degrees.

## Drawing a Circle

A circle is a plane figure obtained by moving and turning continuously through 360 degrees.

You can draw a circle by moving some steps and turning 1 degree (either clockwise or counter-clockwise direction), 360 times. The radius of the circle depends on the size of the steps taken. More the size of each step, more will be the radius and hence larger will be the circle.

## Drawing an Equilateral Triangle

An equilateral triangle is a three sided figure, where all the sides are equal and measure of each of the three angles is 60 degrees. Note that each of the exterior angles of an equilateral triangle is 120 degrees.

## Drawing a Regular Polygon

A polygon is a plane figure formed by a finite number of straight lines called sides or edges. A figure with ‘n’ sides is called an n-sided polygon. Triangle is also a polygon with 3 sides.

A polygon is called a regular polygon if all its sides and angles are equal. An equilateral triangle is a regular 3-sided polygon. Similarly a square is a regular 4-sided polygon.

You can draw an n-sided polygon by taking its exterior angle as (360/n) degrees.

### Pentagon

A pentagon has 5 sides, therefore, each exterior angle of a regular polygon will be (360/5) = 72 degrees.

You can draw a regular pentagon by moving some steps and turning 72 degrees (either clockwise or counter-clockwise direction), 5 times (Exterior angle of regular pentagon is 72 degrees). The size of the pentagon depends on the size of the steps taken. The larger the size of each step, the larger will be the pentagon.