
Pythonを学ぼう! -Turtle編②-
今日も Turtle でお絵描き〜
今回は Google Colaboratory で Turtle を使ってみました!
Google Colaboratory で Turtle を使う時の魔法の言葉👇
(これをはじめに入れないとダメらしい)
!pip3 install ColabTurtle
from ColabTurtle.Turtle import *
どうしてもコッホ曲線が描きたい!
そんな時は、これ👇をコピペすればできるらしい!
def koch(length, depth):
#print(length, depth)
if depth == 0:
forward(length)
else:
koch(length, depth-1)
right(60)
koch(length, depth-1)
left(120)
koch(length, depth-1 )
right(60)
koch(length, depth-1 )
clear()
color('green')
bgcolor('white')
penup()
goto(400, 200)
pendown()
koch(1, 8)
出来上がった図形はこんな感じ👇

うまくいく時とうまくいかない時があるけど…;;
そのほかにもイチョウを描いたりしたよー
参考:https://udemyfun.com/python-apply-turtle/