언어/python
turtle - 사사분면
파아랑새
2018. 3. 3. 11:54
# function
import turtle as t
pen = t.Pen()
def currentPos(x, y):
print ("x => {} y => {}".format(x, y))
pen.penup()
# 1사분면
if x < 0 and y > 0 :
pen.setposition(x, y)
pen.pendown()
pen.circle(30)
# 2사분면
elif x > 0 and y > 0:
pen.setposition(x, y)
pen.pendown()
for i in range(3):
pen.fd(50)
pen.right(angle=120)
# 3사분면
elif x > 0 and y < 0:
pen.setposition(x, y)
pen.pendown()
for i in range(4):
pen.fd(50)
pen.right(angle=90)
# 4사분면
elif x < 0 and y < 0:
pen.setposition(x, y)
pen.pendown()
for i in range(5):
pen.fd(50)
pen.right(angle=144)
t.onscreenclick(currentPos)
t.mainloop()
upgrade
# function
import turtle as t
import random as r
nData = ["yellow", "red", "#aa93e2", "#7798ff"]
mData = ["#eed2ee", "yellow", "blue", "pink", "red", "#4e8672"]
pen = t.Pen()
t.bgcolor("black")
def currentPos(x, y):
print ("x => {} y => {}".format(x, y))
pen.penup()
indx = r.randint(0, 3)
indx1 = r.randint(0, 5)
pen.fillcolor(mData[indx1])
# 1사분면
if x < 0 and y > 0 :
pen.setposition(x, y)
pen.pendown()
pen.begin_fill()
pen.pencolor(nData[indx])
pen.pensize(width=5)
pen.circle(30)
pen.end_fill()
# 2사분면
elif x > 0 and y > 0:
pen.setposition(x, y)
pen.pendown()
pen.begin_fill()
pen.pencolor(nData[indx])
pen.pensize(width=5)
for i in range(3):
pen.fd(50)
pen.right(angle=120)
pen.end_fill()
# 3사분면
elif x > 0 and y < 0:
pen.setposition(x, y)
pen.pendown()
pen.begin_fill()
pen.pencolor(nData[indx])
pen.pensize(width=5)
for i in range(4):
pen.fd(50)
pen.right(angle=90)
pen.end_fill()
# 4사분면
elif x < 0 and y < 0:
pen.setposition(x, y)
pen.pendown()
pen.begin_fill()
pen.pencolor(nData[indx])
pen.pensize(width=5)
for i in range(5):
pen.fd(50)
pen.right(angle=144)
pen.end_fill()
t.onscreenclick(currentPos)
t.mainloop()