눈사람

10144 단어
John Zelle이 만든 그래픽 모듈을 사용하여 눈사람을 그리는 간단한 프로그램입니다.

# exercise_4.py
#   This program draws a winter scene with a Christmas treee and a snowman
# by: Scott Gordon


from graphics import *

# Create main window
def main():
    win = GraphWin("Snowman", 800, 600)
    win.setCoords(-8, -8, 6, 6)
    win.setBackground("grey")
    center = Point(0, 0)

# Draw horizon line and color upper half blue and bottom half white
    horizon = Line(Point(-8, 0), Point(8, 0))
    horizon.setWidth(2)
    horizon.draw(win)

    sky = Rectangle(Point(-8, 0), Point(8, 6))
    sky.setFill("blue")
    sky.draw(win)

# Add triangle for tree and color green
    tree_top = Polygon(Point(-3, 4), Point(-5, -4), Point(-1, -4))
    tree_top.setFill("green")
    tree_top.draw(win)

# Add rectangle for tree bottom and color brown
    tree_bottom = Rectangle(Point(-2.5, -4), Point(-3.5, -5))
    tree_bottom.setFill("brown")
    tree_bottom.draw(win)


# Stack 3 circles each smaller than the next moving up the y coord
    snowman_bottom = Circle(Point(2, -4), 2)
    snowman_bottom.setFill("White")
    snowman_bottom.draw(win)

    snowman_mid = Circle(Point(2, -2), 1.5)
    snowman_mid.setFill("White")
    snowman_mid.draw(win)

    snowman_top = Circle(Point(2, -.5), 1)
    snowman_top.setFill("White")
    snowman_top.draw(win)


# Draw snowman's face on the top circle
    snowman_eye1 = Circle(Point(2.25, -.75), .10)
    snowman_eye1.setFill("Black")
    snowman_eye1.draw(win)

    snowman_eye2 = snowman_eye1.clone()
    snowman_eye2.move(-.75, 0)
    snowman_eye2.draw(win)

    snowman_nose = Polygon(Point(1.75, -1.0), Point(2.0, -1.25), Point(1.95, -1.0))
    snowman_nose.setFill("Orange")
    snowman_nose.draw(win)

    win.getMouse()
    win.close()


main()






좋은 웹페이지 즐겨찾기