#학번 / xxx / 미디어기술콘텐츠학과 import turtle #터틀 그래픽 모듈을 불러옴 import random #난수 모듈을 불러옴 t= turtle.Turtle() # 터틀을 t로 선언( t를 이용해 터틀을 제어할 수 있음) radius = random.randrange(100, 200) #randrange는 랜덤한 범위 내에서 값을 꺼내올 수 있다. (반지름) weight = random.randrange(10, 15) #선의 굵기 t.shape("turtle") #t(터틀)의 모양을 거북이로 바꿈 colorline = ["red","blue","yellow","magenta","cyan","green","purple","gray","brown","navy"] #색리스트 작성 t.up() #위치 이동에 피해입지 않도록 펜을 듬 t.pensize(weight) #t(터틀)이 이동하는 방향에 그려진 선의 굵기를 정해줌 #글 작성 t.goto(0,300) t.write("xxx 과제1", align="center", font=("Arial", 20, "bold")) t.goto(0,280) t.write("한 변 길이 또는 반지름 : "+str(radius), align="center", font=("Arial", 15, "italic")) t.goto(-75,260) t.write("선 굵기 : "+str(weight), align="center", font=("Arial", 15, "italic")) #글 작성 끝 ipt = turtle.textinput("입력", "입력하시오")#ipt에 값 입력받음. t.goto((-200+(radius*2)),(-300+(radius))) #선이 화면 밖에 나가지 않도록 위치 조정 ################################################## #1번 : 라인 ################################################## if ipt == 'line' : #cl = random.choice(colorline)을 이용하여 리스트에서 랜덤으로 색을 가져옴 # t.pencolor(cl) 를 이용해 선의 색깔을 바꿈 cl = random.choice(colorline) #1. 직사각형 t.pencolor(cl) t.down() for reple in range(2): t.lt(90) t.fd(radius) t.lt(90) t.fd(radius2) t.up() #1.직사각형 끝 #마름모 시작점으로 이동 t.lt(90) t.fd(radius) t.lt(90) t.fd(radius) #마름모 시작점 이동 끝 cl = random.choice(colorline) # 2. 마름모 t.pencolor(cl) t.rt(45) t.down() for reple in range(4): t.fd(radius/2) t.rt(90) t.up() #2. 마름모 끝 #좌측 원 시작점으로 이동 t.lt(45) t.fd(radius) t.lt(90) t.fd(radius/2) #좌측원 시작점 이동 끝 cl = random.choice(colorline) #3. 좌측 원 t.pencolor(cl) t.lt(180) #원이 시작점에서 좌측으로 생기기 때문에 반대로 돌려줌 t.down() t.circle(radius/2) t.up()#3. 좌측 원 끝 #우측원 시작점으로 이동 t.fd(radius/2) t.rt(90) t.fd(radius2) t.rt(90) t.fd(radius/2) #우측원 시작점 이동 끝 cl = random.choice(colorline) #4. 우측 원 t.pencolor(cl) t.down() t.circle(radius/2) t.up()#4. 우측 원 끝 #좌측 삼각형으로 이동 t.fd(radius/2) t.right(90) t.fd(radius*1.5) t.lt(60) #좌측 삼각형으로 이동 끝 cl = random.choice(colorline) #5.좌측 삼각형 t.pencolor(cl) t.down() for reple in range(3): t.fd(radius) t.lt(120) t.up() #5. 좌측 삼각형 끝 #우측 삼각형으로 이동 t.lt(120) t.fd(radius) t.rt(60) #우측 삼각형으로 이동 끝 cl = random.choice(colorline) #6. 우측 삼각형 t.pencolor(cl) t.down() for reple in range(3): t.fd(radius) t.rt(120) t.up() #6. 우측 삼각형 끝 #line 종료 ################################################## #2번 : 면 ################################################## # begin_fill() 은 면을 색칠하기 전에 사용, end_fill()를 사용해 끝점과 연결후 만들어진 도형을 채움 elif ipt == 'fill' : cl = random.choice(colorline) t.fillcolor(cl) #면 색 조정 t.down() t.begin_fill() for reple in range(2): #직사각형 t.lt(90) t.fd(radius) t.lt(90) t.fd(radius2) t.end_fill() t.up() #마름모 위치로 이동 t.lt(90) t.fd(radius) t.lt(90) t.fd(radius) #마름모 작성 cl = random.choice(colorline) t.fillcolor(cl) t.rt(45) t.down() t.begin_fill() for reple in range(4): t.fd(radius/2) t.rt(90) t.end_fill() t.up() #좌측 원 위치로 이동 t.lt(45) t.fd(radius) t.lt(90) t.fd(radius/2) #좌측 원 작성 cl = random.choice(colorline) t.fillcolor(cl) t.lt(180) t.down() t.begin_fill() t.circle(radius/2) t.end_fill() t.up() #우측 원 위치로 이동 t.fd(radius/2) t.rt(90) t.fd(radius2) t.rt(90) t.fd(radius/2) #우측 원 작성 cl = random.choice(colorline) t.fillcolor(cl) t.down() t.begin_fill() t.circle(radius/2) t.end_fill() t.up() #좌측 삼각형 위치로 이동 t.fd(radius/2) t.right(90) t.fd(radius*1.5) t.lt(60) #좌측 삼각형 작성 cl = random.choice(colorline) t.fillcolor(cl) t.down() t.begin_fill() for reple in range(3): t.fd(radius) t.lt(120) t.end_fill() t.up() #우측 삼각형으로 이동 t.lt(120) t.fd(radius) t.rt(60) #우측 삼각형 시작 cl = random.choice(colorline) t.fillcolor(cl) t.down() t.begin_fill() for reple in range(3): t.fd(radius) t.rt(120) t.end_fill() t.up() #fill 종료 ################################################## #3번 : 전부 색 넣기 ################################################## elif ipt == 'all' : cl = random.choice(colorline) t.color(cl) cl = random.choice(colorline) t.fillcolor(cl) t.down() t.begin_fill() for reple in range(2): #직사각형 t.lt(90) t.fd(radius) t.lt(90) t.fd(radius2) t.end_fill() t.up() #마름모 위치로 이동 t.lt(90) t.fd(radius) t.lt(90) t.fd(radius) #마름모 작성 cl = random.choice(colorline) t.color(cl) cl = random.choice(colorline) t.fillcolor(cl) t.rt(45) t.down() t.begin_fill() for reple in range(4): t.fd(radius/2) t.rt(90) t.end_fill() t.up() #좌측 원 위치로 이동 t.lt(45) t.fd(radius) t.lt(90) t.fd(radius/2) #좌측 원 작성 cl = random.choice(colorline) t.color(cl) cl = random.choice(colorline) t.fillcolor(cl) t.lt(180) t.down() t.begin_fill() t.circle(radius/2) t.end_fill() t.up() #우측 원 위치로 이동 t.fd(radius/2) t.rt(90) t.fd(radius2) t.rt(90) t.fd(radius/2) #우측 원 작성 cl = random.choice(colorline) t.color(cl) cl = random.choice(colorline) t.fillcolor(cl) t.down() t.begin_fill() t.circle(radius/2) t.end_fill() t.up() #좌측 삼각형 위치로 이동 t.fd(radius/2) t.right(90) t.fd(radius*1.5) t.lt(60) #좌측 삼각형 작성 cl = random.choice(colorline) t.color(cl) cl = random.choice(colorline) t.fillcolor(cl) t.down() t.begin_fill() for reple in range(3): t.fd(radius) t.lt(120) t.end_fill() t.up() #우측 삼각형으로 이동 t.lt(120) t.fd(radius) t.rt(60) #우측 삼각형 시작 cl = random.choice(colorline) t.color(cl) cl = random.choice(colorline) t.fillcolor(cl) t.down() t.begin_fill() for reple in range(3): t.fd(radius) t.rt(120) t.end_fill() t.up() #all 종료
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question