본문 바로가기

정보교과서

[고등학교 정보교과서] 3-3-6. 함수 #3 - 씨마스

고등학교 정보교과서 3. 문제 해결과 프로그래밍 (3) 프로그래밍 Programming ⑥ 함수 Function #3 - 씨마스

고등학교 정보교과서 3. 문제 해결과 프로그래밍 (3) 프로그래밍 Programming ⑥ 함수 Function #3 - 씨마스

 


 

 

하트 만들기

하트만들기 프로그램 실행결과

전체 코드 보기

더보기
# 하트 출력 프로그램

from turtle import *

def heart(y, x, n) :
    for i in range(n) :
        dx = x * 20
        dy = -y * 20
        goto(dx, dy)
        color("orange")
        dot(20)
        x += 1

penup()

heart(0, 1, 2)
heart(0, 6, 2)
heart(1, 0, 4)
heart(1, 5, 4)
heart(2, 0, 9)
heart(3, 0, 9)
heart(4, 1, 7)
heart(5, 2, 5)
heart(6, 3, 3)
heart(7, 4, 1)

exitonclick()   # 화면 클릭시 종료

 

원 그리기

원 그리기 프로그램 실행결과 콘솔
원 그리기 프로그램 실행결과 그래픽

전체 코드 보기

더보기
# 원 그리기 프로그램

from turtle import *

# 원 그리기 메소드
def drawCircle(x, y, r, n) :
    penup()

    for i in range(n) :
        goto(x, y)  # 초기좌표
        setheading(360 / n * i)     # 원 그릴 각도
        color("deep sky blue")
        pendown()
        circle(r)
        penup()

    penup()
    hideturtle()

    exitonclick()

coor = input('x,y형태의 시작 좌표를 입력하세요(ex. 0,0) > ')
x = int(coor.split(",")[0])
y = int(coor.split(",")[1])

r = int(input('반지름을 입력하세요 > '))
n = int(input('그릴 원 개수를 입력하세요 > '))

drawCircle(x, y, r, n)

 

별 작도하기

별 작도하기 실행결과

전체 코드 보기

더보기
from turtle import *

print('============ 별 작도하기 프로그램 ============')

# 별 그리기
def drawStar(size, c) :
    color(c)
    penup()

    goto(0, 0)
    forward(200)
    left(90)

    circle(200, 30)
    right(90)

    pendown()
    tracer(False)
    begin_fill()
    for i in range(5) :
        right(144)
        forward(size)
    
    end_fill()
    tracer(True)

colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple']

cnt = 0
while cnt < 12 :
    drawStar(80, colors[cnt % 7])
    cnt += 1

exitonclick()
728x90