1
3

【Python】turtleで図形描いてみた

Posted at

本日のブログ内容

今日はPythonでいろんな図形を描いてみたのでコードと描いてみた図形を記録として残そうと思います。

三角形

image.png

実際のコード

turtle.color('red', 'yellow')
turtle.begin_fill() # 線の色
for i in range(3):
    turtle.forward(100)
    turtle.left(360 / 3) # 左に3回曲がる
turtle.done()

四角形

image.png

実際のコード

turtle.color('red', 'yellow')
turtle.begin_fill() # 線の色
for i in range(4):
    turtle.forward(100)
    turtle.left(360 / 4) # 左に四回曲がる。
turtle.done()

Untitled.png

実際のコード

turtle.color('black', 'yellow')
turtle.begin_fill() # 線の色
for _ in range(5):
    turtle.forward(200)
    turtle.right(360 / 5 * 2)
turtle.end_fill() # 囲まれ中の色
turtle.done()

星(ver2.0)

Untitled (1).png

実際のコード

turtle.color('black', 'yellow')
turtle.begin_fill() # 線の色
for _ in range(7):
    turtle.forward(200)
    turtle.right(360 / 5 * 2 + 10)
turtle.end_fill() # 囲まれ中の色
turtle.done()

六角形

Untitled (2).png

実際のコード

turtle.color('red', 'yellow')
turtle.begin_fill() # 線の色
for i in range(6 * 10):
    turtle.forward(100)
    turtle.fd(i)
    turtle.right(360 / 6)
turtle.done()

薔薇?

Untitled (3).png

実際のコード

turtle.color('black', 'red')
turtle.begin_fill()
for i in range(200):
    turtle.fd(i)
    turtle.left(360 / 4 + 10)
turtle.end_fill()
turtle.done()
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3