2012년 4월 7일 토요일

Exercise 3.2-Answer

from: http://openbookproject.net/thinkcs/python/english3e/hello_little_turtles.html#exercises

Write a program to draw a face of a clock that looks something like this:

_images/tess_clock1.png

 

  1: # -*- coding: UTF-8 -*-
  2: #!/usr/bin/env python
  3: 
  4: import turtle           # turtle을 사용할 수 있도록 한다.
  5: 
  6: wn = turtle.Screen()
  7: wn.title("A face of a clock")
  8: wn.bgcolor("lightgreen")
  9: 
 10: alex = turtle.Turtle()
 11: alex.pensize(3)
 12: alex.speed(0)
 13: alex.shape("turtle")
 14: alex.color("blue")
 15: 
 16: for i in range(12):
 17:     alex.penup()
 18:     alex.forward(80)
 19:     alex.pendown()
 20:     alex.forward(10)
 21:     alex.penup()
 22:     alex.forward(30)
 23:     alex.stamp()
 24:     alex.backward(120)
 25:     alex.right(30)
 26: 
 27: alex.stamp()
 28: 
 29: wn.mainloop()           # 사용자가 윈도우를 닫을 때까지 기다린다.
 30: 

댓글 없음:

댓글 쓰기