728x90
반응형
(문제)
아래 코드로 집 그리기. 코드 유지하고 ()의 값만 변경하여 다른 크기의 집을 왼쪽에 그리기
import turtle
t=turtle.Turtle()
t.penup()
t.goto(-200,0)
t.pendown()
t.color("lightblue")
t.begin_fill()
for i in range(2):
t.fd(400)
t.rt(90)
t.fd(300)
t.rt(90)
t.end_fill()
t.penup()
t.goto(-200,0)
t.pendown()
t.color("steelblue")
t.begin_fill()
t.goto(0,200)
t.goto(200,0)
t.goto(-200,0)
t.end_fill()
t.penup()
t.goto(-50,-150)
t.pendown()
t.color("lightsteelblue")
t.begin_fill()
for i in range(2):
t.fd(100)
t.rt(90)
t.fd(150)
t.rt(90)
t.end_fill()
(방법)
import turtle
def draw_house(x, y, mag): # 좌표x,y 그리고 배율(1=100%, 0.5=50%)
t=turtle.Turtle()
t.penup()
t.goto(x,y)
t.pendown()
t.color("lightblue")
t.begin_fill()
for i in range(2):
t.fd(400*mag)
t.rt(90)
t.fd(300*mag)
t.rt(90)
t.end_fill()
t.penup()
t.goto(x,y)
t.pendown()
t.color("steelblue")
t.begin_fill()
t.goto(x+(200*mag),y+(200*mag))
t.goto(x+((200*mag)*2),y)
t.goto(x+(200*mag),y)
t.end_fill()
t.penup()
t.goto(x+(150*mag),y-(150*mag))
t.pendown()
t.color("lightsteelblue")
t.begin_fill()
for i in range(2):
t.fd(100*mag)
t.rt(90)
t.fd(150*mag)
t.rt(90)
t.end_fill()
draw_house(-200, 0, 1) # x,y 좌표와 배율
draw_house(-600, 0, 0.5)
draw_house(400,-100, 0.3)
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 문제 : 터틀(turtle)로 무지개 그리기 (0) | 2023.04.09 |
---|---|
[파이썬] 문제 : 문자열의 대문자,소문자 변환 및 문자 찾기 (0) | 2023.04.09 |
[파이썬] 문제 : 가변인자 함수로 출력하기 (0) | 2023.04.09 |
[파이썬] 문제 : fiveTen 함수. 5이하, 5에서 10사이, 10초과 구하기 (0) | 2023.04.09 |
[파이썬] 문제 : sum, sub, average 함수 (0) | 2023.04.09 |
댓글