프로그래밍

파이썬 나무 그리기

작성자 정보

  • PHP8 작성
  • 작성일

컨텐츠 정보

  • 3,742 조회
  • 1 추천
  • 0 비추천
  • 목록

본문

from turtle import *
from random import *

t1 = Turtle()
t2 = Turtle()
t3 = Turtle()
t4 = Turtle()
t5 = Turtle()

x = -200
turtles = [t1,t2,t3,t4,t5]
for t in turtles:
  t.speed('fastest')
  t.left(90)
  t.color('brown')
  t.pu()
  x += randint(80,160)
  t.goto(x, randint(-100,100))
  t.pd()


def branch(turt, branch_len):
  angle = randint(22,30)
  sf = uniform(0.6,0.8)
  size = int(branch_len /10)
  turt.pensize(size)
  if branch_len < 20:
    turt.color('green')
    turt.stamp()
    turt.color('brown')
  if branch_len > 10:
    turt.forward(branch_len)
    turt.left(angle)
    branch(turt, branch_len*sf)
    turt.right(angle*2)
    branch(turt, branch_len*sf)
    turt.left(angle)
    turt.backward(branch_len)

for t in turtles:
  branch(t,100)




8192233530e72746f9c4e903d780b717_1616333308_8548.png
 


관련자료

댓글 0
등록된 댓글이 없습니다.

최근 글


새 댓글


알림 0