728x90
반응형
import turtle
t = turtle.Turtle()
t.hideturtle()
t.width(3)
def get_length(base, height): # 빗변 길이. hypotenuse
return math.sqrt(base**2 + height**2)
def get_angle(base, height): # 각도 계산
angle = math.atan(height / base)
return angle * 180 / math.pi
def draw_ㄱ(x, y, width, height): # 사각형 내에서 그린다고 할때 좌상단이 x, y 좌표. 가로축 width, 높이 height
t.penup() # 이동할때 선이 그려지지 않도록 펜을 듬
t.goto(x, y) # x,y 좌표로 이동
t.pendown() # 그리기 위해 펜을 내림
t.setheading(0) # 펜의 방향 초기화(우측). 이를 초기화하기 않으면 매번 다른 글자 쓸때마다 방향이 달라서 그리기 어려움
t.forward(width) # width 만큼 선을 그림. ㄱ의 ㅡ
t.right(90) # 오른쪽으로 90 회전
t.forward(height) # height 만큼 선을 그림 ㄱ의 ㅣ
def draw_ㅂ(x, y, width, height):
t.penup()
t.goto(x, y)
t.pendown()
t.setheading(0)
t.right(90)
t.forward(height)
t.backward(int(height/2))
t.left(90)
t.forward(width)
t.left(90)
t.forward(int(height / 2))
t.backward(height)
t.left(90)
t.forward(width)
def draw_ㅏ(x, y, width, height):
t.penup()
t.goto(x, y)
t.pendown()
t.setheading(0)
t.right(90)
t.forward(int(height/2))
t.left(90)
t.forward(width)
t.backward(width)
t.right(90)
t.forward(int(height / 2))
def draw_ㅅ(x, y, width, height):
t.penup()
y1 = y-(height) # ㅅ에서 좌측 하단으로 이동하기 위해 y계산(세로축)
t.goto(x, y1)
t.pendown()
t.setheading(0)
angle = get_angle(int(round(width/2,1)), height) # 직각삼삭형에서 높이와 밑변 길이를 알때 각도 계산
angle2 = 180 - (90 + angle) # ㅅ의 좌측 하단에서 중앙상단으로 이동 후 내려가는 각도 계산
length = get_length(int(round(width/2,1)), height) # 긱각삼걱형에서 높이와 밑변 길이를 알때 빗변 길이 계산
t.left(angle) # ㅅ의 / 의 각도 바꿈
t.forward(length) # ㅅ의 / 의 길이는 삼각형의 빗변 길이로 사용
t.right(180) # ㅅ의 / 이후 ∖ 각도 계산을 위해서 먼저 / 방향으로 회전
t.left(angle2 * 2) # 직각삼각형(ㅅ을 직각삼각형 2개로 봄)에서 왼쪽 직각삼각형에서 90, angle 그리고 하나는 180-(90+angle). 이 각도를 2번 하면 계산됨
t.forward(length) # ㅅ에서 ∖ 그림
def draw_ㅣ(x, y, width, height): # 한글 ㅣ (이)
t.penup()
t.goto(x, y)
t.pendown()
t.setheading(0)
t.right(90)
t.forward(height)
def draw_ㅇ(x, y, width, height):
t.penup()
# t.goto(x+(int(width/2)), y-(int(height/2)))
t.goto(x, y-(int(height/2)))
t.pendown()
t.circle(width / 2)
def draw_ㅕ(x, y, width, height):
t.penup()
t.goto(x+(width), y)
t.pendown()
t.setheading(0)
t.right(90)
t.forward(int(height/3))
t.right(90)
t.forward(width)
t.backward(width)
t.left(90)
t.forward(int(height/3))
t.right(90)
t.forward(width)
t.backward(width)
t.left(90)
t.forward(int(height/3))
def draw_ㄴ(x, y, width, height):
t.penup()
t.goto(x, y)
t.pendown()
t.setheading(0)
t.right(90)
t.forward(height)
t.left(90)
t.forward(width)
# 예시로 (50, 50) 위치에 폭 100, 높이 150 크기의 'ㄱ'을 그립니다.
# draw_ㄱ(-100, 0, 60, 60)
draw_ㅂ(-150, 0, 70, 60)
draw_ㅏ(-70, 0, 20, 60)
draw_ㄱ(-150, -70, 80, 30)
draw_ㅇ(-40, 0, 60, 60)
draw_ㅕ(30, 0, 20, 60)
draw_ㄴ(-40, -70, 90, 30)
draw_ㅅ(70, 0, 60, 60)
draw_ㅣ(160, 0, 10, 60)
draw_ㄴ(70, -70, 90, 30)
turtle.done()
try:
turtle.bye()
except:
print("bye")
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 문제 : example.txt 파일의 $ 문자를 # 문자로 변경 (0) | 2023.05.29 |
---|---|
[파이썬] 문제 : 영단어 퀴즈 만들기 (0) | 2023.05.28 |
[파이썬] 문제 : 크롤링에서 특정 데이터만 가져오기(네이버 재무정보) (2) | 2023.05.27 |
[파이썬] 문제 : 추상클래스 Polygon과 자식클래스 Rectangle (0) | 2023.05.27 |
[Rust] UI : 입력 받고 버튼 클릭시 Msg 보이기(native-windows-gui) (0) | 2023.05.27 |
댓글