開発環境
- OS X Yosemite - Apple (OS)
- Emacs (Text Editor)
- Python 3.4 (プログラミング言語)
Python for Kids: A Playful Introduction to Programming (Jason R. Briggs (著) 、No Starch Press)のPart Ⅰ.(Learning to Program)、Chapter 11.(More Turtle Graphics)、Programming Puzzles #3: Another Star-Drawing Function(No. 3103)を解いてみる。
Programming Puzzles #3: Another Star-Drawing Function(No. 3103)
コード(Emacs)
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import turtle
t = turtle.Pen()
t.speed(0)
def draw_star_only_left(size=100, points=5):
angle = 360 / points
for x in range(points):
t.forward(size)
t.left(180 - angle)
t.forward(size)
t.left(180 + 2 * angle)
def draw_star(size=100, points=5):
angle = 360 / points
for x in range(points):
t.forward(size)
t.left(180 - angle)
t.forward(size)
t.right(180 - 2 * angle)
for points in range(5, 10):
draw_star_only_left(points = points)
t.reset()
draw_star(points=points)
t.reset()
draw_star(size=50, points=50)
入出力結果(Terminal, IPython)
$ ./sample3.py $
0 コメント:
コメントを投稿