본문 바로가기
프로그래밍/Python_AI(영상처리)

영상처리 사전지식 1 : turtle 함수 // 나무 가지 그리기

by Royal! 2020. 12. 2.
728x90
반응형

#나무 가지 그리기
import turtle as t

def branch(pos, angle, lenth, thick): 
    if lenth < 10 : return
    t.penup() #위
    t.goto(pos) # 그리기
    t.pendown() #아래
    t.setheading(angle) # 각도
    t.pensize(thick) # 굵기 
    t.forward(lenth) 
    pos_new = t.pos() #재귀함수
    branch(pos_new, angle+25, lenth*0.75, thick*0.75)
    branch(pos_new, angle-15, lenth*0.8, thick*0.75)
    
t.hideturtle() #화살표 숨기기
t.speed(0) # 빠르게 그리기
t.setundobuffer(None)
t.tracer(10000,0) # 10000번 forward하고 나서 한번
branch((0, -700), 90,300, 30)

 


컬러 넣기 import colorsys (참조 : www.vagrearg.org/content/hsvrgb)

import colorsys

import math

 

hue = math.log10(lenth) * - 0.17 + 0.52
color = colorsys.hsv_to_rgb(hue, 0.7, 0.8) 

t.pencolor(color)


- 최종 코드

728x90
반응형