# 【turtle】Drawing with Python!(For beginners)

スポンサーリンク

Hello, this is Yuki (@engineerblog_Yu), a student engineer.

I’m not sure how to program, but I’m sure it’s all in code!

I want to teach programming to my child easily.

I want to learn programming in a fun way!

Are you one of those who want to learn programming in a fun way?

In this article, we will use a Python library called turtle to make drawing fun.

I’ve made it as simple as possible, so you can relax and take a look at it.

スポンサーリンク

## Drawing with TURTLE

turtle is a Python library and graphics tool.

If you don’t know what it means, just know that you are going to use a Python application called turtle.

First, let’s find a terminal.

Terminal is an app like this on a Mac.

On Windows, it is the command line.

First, type python in the terminal and press Enter.

You will then see a long sentence, but it is OK to ignore it.

Next, type import turtle and press Enter.

## move forward

To move forward, we use this syntax.

100 means to move forward 100.

You can put in as much value as you want to move forward.

turtle.forward(100)

## move backward

turtle.backward(100)

## turn

When turning, either RIGHT or LEFT is used.

The angle is specified in parentheses.

The code below means to turn 90 degrees to the right.

turtle.right(90)

Now let’s execute this code.

turtle.forward(50)
turtle.right(90)
turtle.forward(100)

Go 50, turn right and go 100.

## make a circle

Next, let’s draw a circle.

The code here is to draw a circle with a radius of 100.

turtle.circle(100)

turtle.home()

turtle.clear()

## Terminate

turtle.done()

## Draw patterns in conjunction with Python syntax.

Let’s draw various shapes.

This time, we will run it in the main file.

(You will need to have a Python environment to execute this code, so just be aware that you can do it like this.)

In the main file, write the following statement and enter python main.py in the terminal.

import turtle

turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.done()
import turtle

for i in range(5):
turtle.forward(100)
turtle.right(360/5*2)

turtle.done()
import turtle

for i in range(35):
turtle.forward(100+i*10)
turtle.right(360/3+i)

turtle.done()

I think you can learn programming while having fun because you can easily draw various patterns.