# Learn To Create Line Patterns in Scratch Using 2D Shapes

This post is also available in: हिन्दी (Hindi)

You can create wonderful designs and pattern in Scratch using Pen blocks. In this article you will learn to create line patterns in Scratch.

## What is a Shape in Geometry?

In geometry, a shape can be defined as the form of an object or its outline, outer boundary, or outer surface. These shapes are of two types – two-dimensional (2D) or three-dimensional (3D).

A 2D shape has only two dimensions – length and width, whereas a 3-D shape has three dimensions – length, width, and height.

Examples of 2D shapes are square, rectangle, triangle, circle, pentagon, etc.

And the examples of 3D shapes are cube, cuboid, sphere, cylinder, cone, pyramid, prism, etc.

## What is a Pattern?

A pattern is a repeated design or a recurring sequence of an ordered set of numbers, shapes or other mathematical objects, arranged according to some rule.

A number pattern is a sequence that follows a certain sequence or pattern. Some of following number patterns are:

1, 4, 7, 10, 13, 16, … starts at 1 and jumps 3 every time.

1, 4, 9, 16, 25, 36, … starts with 12, followed by 22, 32, and so on.

A geometric pattern is a kind of sequence formed of geometric shapes and typically repeated like a wallpaper design. Some of the examples of the geometric pattern are:

## Creating Geometric Patterns in Scratch

You can make use of the ‘Pen’ tool in Scratch to create amazing geometric patterns. The first step in creating these patterns is that two basic knowledge are required

• drawing 2D figures such as square, rectangle, triangle, circle, pentagon, etc.
• looping i.e., the repeat block for repetition of 2D figures.

With the ‘Pen’ extension, coding to draw a shape is very simple with some basic knowledge of geometry. Furthermore, amazingly complex patterns can be constructed with just a few colourful blocks of code. With the pen tool, the possibilities are immense and incredibly exciting. With your imagination coupled with your creativity, the patterns you can come up with are simply enormous.

## Patterns With Straight Line

A straight line can be drawn in the following four ways – horizontal line, vertical line, left slanting line and right slanting line.

### Drawing a Horizontal Line

To draw a horizontal line of length 200 units from a point (x1, y1), first of all, place the sprite at the position (x1, y1) and then point the sprite in the direction 90 and then move 200 steps.

### Drawing a Vertical Line

To draw a vertical line of length 200 units from a point (x1, y1), first of all, place the sprite at the position (x1, y1) and then point the sprite in the direction 90 and then turn 90 degrees and finally move 200 steps.

### Drawing a Left Slanting Line

To draw a left-slanting line of length 200 units from a point (x1, y1), first of all, place the sprite at the position (x1, y1) and then point the sprite in the direction 90 and then turn 45 degrees (angle depends on the inclination of slanting line with the horizontal) and finally move 200 steps.

Note that when the angle of rotation is positive, then the line drawn is left slanted.

### Drawing a Right Slanting Line

To draw a right-slanting line of length 200 units from a point (x1, y1), first of all, place the sprite at the position (x1, y1) and then point the sprite in the direction 90 and then turn -45 degrees (angle depends on the inclination of slanting line with the horizontal) and finally move 200 steps.

Note that when the angle of rotation is negative, then the line drawn is right slanted.

Now, let’s draw the basic unit of a snowflake as shown in the figure below.

Now, it’s time to draw a complete snowflake. To do so, repeat the above code 6 times (using repeat block) and after each step turn 60 degrees (6 × 60 = 360 degrees, will complete one circle).

Note that 150 steps is changed to 120 steps and 50 steps changed to 40 steps, just to fit it best on the stage.

Now, you can repeat the above code to draw a pattern consisting of snowflakes. In the following, the above code is repeated 10 times and after each iteration the centre point of the next snowflake is moved 40 steps ahead.

Let’s now draw colourful snowflakes.

The following code will draw the above pattern:

## Some More Patterns Using Lines

### Rainbow Pattern

Rainbow pattern consisting of different coloured lines can be drawn by drawing a straight line and repeating the process by changing the direction and colour of the line.

### Floral Pattern

Let’s first see how to draw a single unit (leaf) of the above pattern.