# data[].attributes.body
ฝึกวาดรูปโดยใช้ module turtle
เอกสารอ้างอิง
https://docs.python.org/3/library/turtle.html

# data[].attributes.attachment_link.readable_text
Learn how to draw shapes in python with this free python web tutorial.

STEP 1
Run the following code:

The above code will create a square using the the turtle library in Python.

Let's explore the code:

1. import turtle (Imports the turtle library)

2. window = turtle.Screen() (Creates a new blank canvas to draw on)

3. timmy = turtle.Turtle() (Creates a new turtle called timmy)

4. timmy.forward(100) (Move the turtle forwad 100 steps)

5. timmy.right(90) (Rotates the turtle right by 90 degrees)

6. timmy.forward(100) (Move the turtle forwad 100 steps)

7. timmy.right(90) (Rotates the turtle right by 90 degrees)

8. timmy.forward(100) (Move the turtle forwad 100 steps)

9. timmy.right(90) (Rotates the turtle right by 90 degrees)

10. timmy.forward(100) (Move the turtle forwad 100 steps)

11. timmy.right(90) (Rotates the turtle right by 90 degrees)​

Below are the basic commands for drawing shapes in Python:

forward (Move the turtle forward)

backward (Move the turtle backwards)

right (Right turn)

left (Left turn)

penup (Pen up)

pendown (Pen down)

pensize (Change the size of the pen)

pencolor (Change the pen colour)

Using the sample code (above) draw each of the following shapes:

Use the code window above to test your code for each shape. Bonus Challenge
Finished? Try to draw the following shape:

STEP 3
Can you identify the repeating pattern in the first example (shown above)?

Answer: The instructions forward(100) + right(90) are repeated 4 times!

We can optimise our code by 'using a loop'. For example .
Optimised code for creating a square Final challenge
Optimise each of your solutions for each of the shapes (above) by using loops.

Python web, python programming language, python programming, python coding, turtle, python turtle​

# data[].attributes.attachment_link.keywords[]
free remote teaching resources and activities for teaching computer science.

# data[].attributes.attachment_link.title
Anyone for a game of 'Code Golf'? - FORE!

# data[].attributes.attachment_link.description
Brief introduction to programming using Python's turtle library.

# data[].attributes.body
กราฟแสดงความสัมพันธ์ระหว่าง cases,deaths,recovered ของทวีป Asia, Europe, North America
https://disease.sh/v3/covid-19/continents

# data[].attributes.body
กราฟแสดงความสัมพันธ์ระหว่าง case,todaycase,deaths และ todayDeaths ของรัฐนิวยอร์ก รัฐโอไฮโอและรัฐไอโอวา
https://disease.sh/v3/covid-19/states

# data[].attributes.body
กราฟแสดงวันที่และจำนวนผู้เสียชีวิต
https://disease.sh/v3/covid-19/nyt/usa

# data[].attributes.body
กราฟแสดความสัมพันธ์ระหว่าง updated และ todaycase
https://disease.sh/v3/covid-19/continents

# data[].attributes.body
กราฟแสดงจำนวนผู้ติดเชื้อและผู้เสียชีวิตของวันที่ 26/10/2021
ของแต่ละทวีป

https://disease.sh/v3/covid-19/continents

# data[].attributes.body
กราฟแสดงจำนวนคนติดเชื้อ เเละผู้เสียชีวิตของทั้ง 4 รัฐ
https://disease.sh/v3/covid-19/states

# data[].attributes.body
https://disease.sh/v3/covid-19/nyt/states?lastdays=30

# data[].attributes.headline
กราฟแสดงวันที่และจำน

# data[].attributes.body
กราฟแสดงวันที่และจำนวนผู้เสียชีวิต
https://disease.sh/v3/covid-19/nyt/usa

# data[].attributes.body
https://disease.sh/v3/covid-19/states

# data[].attributes.body
https://disease.sh/v3/covid-19/states
กราฟแสดงข้อมูลจำนวนผู้ติดเชื้อ ผู้ที่หายป่วย
ผู้เสียชีวิต ของทั้ง4เดือนนี้
!จำนวนคน(หน่วยเป็นล้าน)!

# data[].attributes.body
#วงกลมดอกไม้
import turtle
t = turtle.Turtle()
t.shape('turtle')
t.color('crimson','tomato')
t.width(10)
t.begin_fill()

for i in range(6):
t.circle(100)
t.circle(-100)
t.rt(75)

t.end_fill()

# data[].attributes.body
https://disease.sh/v3/covid-19/nyt/usa
กราฟสัมพันธ์ระหว่า casesจำนวนผู้ป่วยโควิดของ USA  (คน) และ dateเวลา (เดือน/วัน/ปี)

# data[].attributes.body
https://disease.sh/v3/covid-19/countries

# data[].attributes.body
https://disease.sh/v3/covid-19/states

# data[].attributes.body
https://disease.sh/v3/covid-19/states

# data[].attributes.body
https://disease.sh/v3/covid-19/states

# data[].attributes.attachment_caption
นำชนิดข้อมูลทั้ง3รัฐมาเปรียบเทียบกันโดยใช้ชนิดข้อมูล3ชนิดได้แก่ deaths , cases และ casesPerOneMillion

# data[].attributes.body
https://disease.sh/v3/covid-19/vaccine/coverage/states?lastdays=30&fullData=false

# data[].attributes.body
from turtle import*
import random
my_color = ['red', 'deeppink', 'aqua', 'magenta', 'gold', 'lime']

print("Hello Turtle")
shape("turtle")
pensize(5)
speed(150)
for i in range(10):
begin_fill()
for i in range(5):
color(random.choice(my_color))
forward(100)
left(72)
left(36)
for i in range(5):
color(random.choice(my_color))
forward(160)
left(144)
color('black')
end_fill()

# data[].attributes.body
https://disease.sh/v3/covid-19/states

เวลาดึงข้อมูลจาก api อยากให้ดึงทุกรัฐ หรือให้เลือกรัฐที่จะดึงมาได้เป็น input จากผู้ใช้ก็ได้ค่ะ

# data[].attributes.body
from turtle import *

def star(distance):

speed(5)

pencolor('white')

my_color = ['orange','yellow','green','blue','purple','red']

for color in my_color:

begin_fill()

fillcolor(color)

right(60)

forward(distance)

for time in range(3):

left(120)

forward(distance)

end_fill()

begin_fill()

fillcolor('pink')

for time in range(6):

right(60)

forward(distance)

end_fill()

star(100)

# data[].attributes.body
https://disease.sh/v3/covid-19/states

เวลาดึงข้อมูลจาก api อยากให้ดึงทุกรัฐ หรือให้เลือกรัฐที่จะดึงมาได้เป็น input จากผู้ใช้ก็ได้ค่ะ

# data[].attributes.attachment_caption
กราฟแสดง จำนวนประชากร จำนวนประชากรที่ได้รับการตรวจ จำนวนประชากรที่ติดโควิด ของทั้ง3รัฐ ใน USA แกน y คือจำนวน แกน x คือ ชื่อรัฐ

# data[].attributes.body
https://disease.sh/v3/covid-19/states

# data[].attributes.body
from turtle import*
import random
my = ["pink"]

color(my)
forward(25)
left(90)
forward(100)
right(90)
forward(50)
right(90)
forward(100)
left(90)
forward(25)
left(90)
forward(125)
left(90)
forward(75)
right(90)
forward(15)
left(90)
forward(25)
left(90)
forward(140)

done()

# data[].attributes.body
from turtle import*

from random import*

my_colour = ['pink','blue','yellow','purple','red','orange']

shape("turtle")

for i in range(6):

color(choice(my_colour))

left(60)

forward(100)

color(choice(my_colour))

right(60)

forward(100)

for i in range(4):

color(choice(my_colour))

left(60)

forward(100)

# data[].attributes.body
from turtle import *
import random
pensize(4)
speed(7)
shape("turtle")
print("Hello teacher")

my_color=["red","pink","orange"]
for i in range(12):
color("black",random.choice(my_color))
begin_fill()
for i in range(3):
forward(150)
left(120)
right(30)
end_fill()

# data[].attributes.body
from turtle import*

import random

color

my_color = ["red", "pink" , "orange","purple" ]

print("Hello,turtle")

shape("turtle")

pensize(2)

speed(5)

for i in range(3):

for i in range(4):

for i in range(6):

color(random.choice(my_color))

forward(60)

left(40)

left(30)

forward(1)

left(1)

# data[].attributes.body
from turtle import*
import random
my_color = ["pink","green","yellow"]
shape("turtle")
color("black")
pensize(2)
speed(2)
begin_fill()
for i in range(8):
forward(100)
right(45)
left(90)
forward(100)
for i in range(8):
right(90)
forward(100)
right(90)
forward(100)
left(135)
forward(100)
color(random.choice(my_color))
end_fill()
done()

# data[].attributes.body
from turtle import *
import random
my_color = ["pink","yellow","orange"]
Screen().bgcolor("blue")
pensize(2)
speed(3)
color("red")
begin_fill()
for i in range(10):
for i in range(2):
forward(100)
right(60)
forward(100)
right(120)
right(36)
color(random.choice(my_color))
end_fill()
done()

# data[].attributes.body
from turtle import *
print(" | |  || || |  | O| ||")
print("WANNAONE")
color('black')
pensize(2)
speed(20)
forward(600)
left(90)
forward(150)
left(90)
dot(11)
forward(200)
right(90)
dot(11)
forward(800)
left(90)
dot(11)
forward(300)
left(45)
dot(11)
forward(300)
left(45)
dot(11)
forward(200)
left(129)
dot(11)
forward(657.8)
left(230.8)
forward(400)
left(222)
forward(310)
left(138.6)
dot(11)
forward(630)
left(152.5)
dot(11)
forward(450)
left(207.2)
forward(405)
left(90)
forward(200)
left(227)
forward(207)
left(282)
forward(310)
left(32)
forward(200)
right(222)
forward(230)
left(75)
forward(160)
left(115)
forward(130)
right(328)
forward(195)
left(89.5)
dot(11)
forward(160)

# data[].attributes.body
from turtle import *

print("Hello, Turtle")
shape("turtle")
pensize(4)
speed(10)

color("blue","blue")
begin_fill()
for i in range(2):
forward(200)
left(90)
forward(130)
left(90)
end_fill()
penup()
goto(200,30)
pendown()
color("red","red")
begin_fill()
forward(15)
left(90)
forward(70)
left(90)
forward(15)
end_fill()
penup()
goto(0,100)
pendown()
color("red","red")
begin_fill()
forward(15)
left(90)
forward(70)
left(90)
forward(15)
end_fill()
penup()
goto(70,130)
pendown()
left(90)
color("yellow","yellow")
begin_fill()
for i in range(2):
forward(15)
right(90)
forward(60)
right(90)
end_fill()
penup()
goto(85,150)
pendown()
color("red","red")
begin_fill()
for i in range(2):
forward(10)
right(90)
forward(30)
right(90)
end_fill()
penup()
goto(30,25)
pendown()
color("yellow","yellow")
begin_fill()
for i in range(2):
forward(80)
right(90)
forward(140)
right(90)
end_fill()
penup()
goto(80,65)
pendown()
color("white","white")
begin_fill()
circle(16,360)
end_fill()
penup()
goto(75,65)
pendown()
color("black","black")
begin_fill()
circle(5,360)
end_fill()
penup()
goto(150,65)
pendown()
color("white","white")
begin_fill()
circle(20,360)
end_fill()
penup()
goto(125,65)
pendown()
color("black","black")
begin_fill()
circle(5,360)
end_fill()
penup()
goto(100,40)
pendown()
color("black","black")
begin_fill()
circle(6,360)
end_fill()
penup()
goto(-100,-10)
pendown()

# data[].attributes.attachment_link.title
ต้นไม้สีสดใส

# data[].attributes.body
from turtle import *
shape('turtle')
width(10)
bgcolor('red')

#Body
def body(line_bd, fill_bd):
color(line_bd, fill_bd)
begin_fill()
rt(90)
fd(80)
circle(-50,180)
fd(200)
circle(-140,180)
fd(200)
circle(-50,180)
fd(80)
lt(90)
fd(80)
end_fill()
# body()

#glass
def glass (line_g, fill_g):
color(line_g, fill_g)
begin_fill()
penup()
goto(80,100)
pendown()
circle(-50,180)
fd(70)
circle(-50,180)
fd(70)
end_fill()
# glass()

#bag
def bag (line_b, fill_b):
color(line_b, fill_b)
begin_fill()
penup()
goto(-100,120)
pendown()
circle(60,90)
fd(40)
circle(60,90)
lt(90)
fd(160)
end_fill()
# bag()

#hat
def party_hatt(line_h, fill_h):
color(line_h, fill_h)
begin_fill()
penup()
goto(-70,220)
pendown()
for i in range(3):
fd(100)
rt(120)
end_fill()
#     done()
# party_hatt()

#Test
body('black', 'red')
glass ('black', 'lightskyblue')
bag ('black', 'red')
party_hatt('black', 'green')

# data[].attributes.body
from turtle import *

import random

my_color1 = ['red','green','yellow']

my_color2 = ['red','blue','purple']

print("Hello,Turtle")

shape("turtle")

pensize(2)

speed(2)

for i in range(2):

color(random.choice(my_color1))

forward(200)

left(90)

stamp()

for i in range(4):

color(random.choice(my_color2))

forward(50)

left(90)

forward(50)

right(90)

stamp()

# data[].attributes.body
from turtle import *

import random

s = ["tan","oat","latte","red","pink","purple","blue","tawny","gray"]

def message_box(x):

color(random.choice(s))

shape("circle")

pensize(3)

speed(10)

forward(x)

right(90)

forward(x)

right(90)

forward(x-(x/4))

left(15)

forward(x/2)

right(165)

forward(x/4)

left(60)

forward(x)

h=int(input())

rr=message_box(h)

print(rr)