Coding/Python 삽질기2008. 6. 21. 02:07

사용자 삽입 이미지

사용자 삽입 이미지

사용자 삽입 이미지



#-*- coding: cp949 -*-
from Tkinter import *
import math
import random
RADIAN = math.pi / 180
aColor = [ "brown", "red", "blue", "green", "orange", "black" ]
def DrawTree( startX, startY, angle, length, depth ):
    if depth == 0:
        return
   
    rand=random.random;
    endX = startX + length * math.cos(angle * RADIAN)
    endY = startY - length * math.sin(angle * RADIAN)
    myCanvas.create_line( startX, startY, endX, endY, width = depth, fill=aColor[int(depth * rand()) % 6])
   
    rand=random.random;
    DrawTree( endX, endY, angle + 30 * rand(), length * (rand() + 0.2), depth - 1 )
    rand=random.random;
    DrawTree( endX, endY, angle - 30 * rand(), length * (rand() + 0.2), depth - 1 )
#----------------------------------------------------------
# main
if __name__ == "__main__": 
    root = Tk()
    scrollbarX = Scrollbar( root, orient = "horizontal" )
    scrollbarY = Scrollbar( root)
  
    myCanvas = Canvas(root, xscrollcommand = scrollbarX.set,  yscrollcommand = scrollbarY.set, confine = 0, scrollregion = (0, 0, 480, 640 ))
   
    scrollbarX.config (command=myCanvas.xview)
    scrollbarY.config (command=myCanvas.yview)
   
    scrollbarX.pack (side=BOTTOM, fill=X)
    scrollbarY.pack (side=RIGHT, fill=Y)
   
    root.configure(width=640, height=640)
    DrawTree(240, 320, 90, 40, 12)
    myCanvas.pack()
    root.mainloop()

'Coding > Python 삽질기' 카테고리의 다른 글

간단한 메모장  (0) 2008.09.14
파일을 HEX 값으로 보여 주는 소스  (0) 2008.05.19
Post it 만들기  (0) 2008.03.04
Posted by chobocho