โ ํฐํ ๊ทธ๋ํฝ ํ๋ก๊ทธ๋จ (๊ธฐ๋ณธ)
import turtle ##ํฐํ๊ทธ๋ํฝ์ฌ์ฉ์์ํ์ฝ์
##
##ํจ์ ์ ์ธ##
##๋ณ์ ์ ์ธ##
myT=None ##์๋ฌด๊ฒ๋์๋ค๋ None ์ผ๋ก ์ด๊ธฐํ##
##๋ฉ์ธ ์ฝ๋##
myT=turtle.Turtle() ##myT ๋ก ํฐํ ๋์
##
myT.shape('turtle') ##๊ฑฐ๋ถ์ด ๋ชจ์ 7๊ฐ์ง##
for i in range(0,4) :
myT.forward(200) ##๊ฑฐ๋ถ์ด๋ฅผ ์์ผ๋ก ์ด๋##
myT.right(90) ##๊ฑฐ๋ถ์ด๋ฅผ ์ค๋ฅธ์ชฝ์ผ๋ก ํ์ ##
turtle.done()
โ ํฐํ ๊ทธ๋ํฝ ํ๋ก๊ทธ๋จ (์์ฉ)
1. ์ผ์ชฝ ๋ง์ฐ์ค : ๊ฑฐ๋ถ์ด๊ฐ ์ ์ ๊ทธ๋ฆผ
2. ์คํฌ๋กค ๋ง์ฐ์ค : ๊ฑฐ๋ถ์ด ํ๋/์ถ์ (์๋ณ๊ฒฝ)
3. ์ค๋ฅธ์ชฝ ๋ง์ฐ์ค : ๊ฑฐ๋ถ์ด๊ฐ ์ ๊ทธ๋ฆฌ์ง ์๊ณ ์ด๋๋งํจ
import turtle
import random
##ํจ์ ์ ์ธ##
def screenLeftClick(x,y) :
global r,g,b
turtle.pencolor((r,g,b))
turtle.pendown()
turtle.goto(x,y)
def screenRightClick(x,y) :
turtle.penup()
turtle.goto(x,y)
def screenMidClick(x,y) :
global r,g,b
tSize = random.randrange(1,10)
turtle.shapesize(tSize)
r=random.random()
g=random.random()
b=random.random()
##๋ณ์ ์ ์ธ##
pSize= 10
r,g,b = 0.0,0.0,0.0
##๋ฉ์ธ ์ฝ๋##
turtle.title('๊ฑฐ๋ถ๊ฑฐ๋ถ ๊ทธ๋ฆผ๊ทธ๋ฆฌ๊ธฐ')
turtle.shape('turtle')
turtle.pensize(pSize)
turtle.onscreenclick(screenLeftClick, 1)
turtle.onscreenclick(screenRightClick, 3)
turtle.onscreenclick(screenMidClick, 2)
turtle.done()
โ ํฐํ ๊ทธ๋ํฝ ํ๋ก๊ทธ๋จ (์์ฉ)
1. ์ผ์ชฝ ๋ง์ฐ์ค : ๊ฑฐ๋ถ์ด๊ฐ ์ ์ ๊ทธ๋ฆผ + ํ๋ ์ถ์ (์๋ณ๊ฒฝ)
3. ์ค๋ฅธ์ชฝ ๋ง์ฐ์ค : ๊ฑฐ๋ถ์ด๊ฐ ์ ๊ทธ๋ฆฌ์ง ์๊ณ ์ด๋๋งํจ
import turtle
import random
##ํจ์ ์ ์ธ##
def screenLeftClick(x,y) :
global r,g,b
turtle.pencolor((r,g,b))
turtle.pendown()
turtle.goto(x,y)
tSize = random.randrange(1,10)
turtle.shapesize(tSize)
r=random.random()
g=random.random()
b=random.random()
def screenRightClick(x,y) :
turtle.penup()
turtle.goto(x,y)
##๋ณ์ ์ ์ธ##
pSize= 10
r,g,b = 0.0,0.0,0.0
##๋ฉ์ธ ์ฝ๋##
turtle.title('๊ฑฐ๋ถ๊ฑฐ๋ถ ๊ทธ๋ฆผ๊ทธ๋ฆฌ๊ธฐ')
turtle.shape('turtle')
turtle.pensize(pSize)
turtle.onscreenclick(screenLeftClick, 1)
turtle.onscreenclick(screenRightClick, 3)
turtle.done()