## 2018年1月26日金曜日

### Python - Loops Are Fun (You Can Say That Again)(SPIRAL ROSETTES, position, heading)

Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming (Bryson Payne(著)、No Starch Press)のChapter 4.(Loops Are Fun (You Can Say That Again))、PROGRAMMING CHALLENGES、#1: SPIRAL ROSETTESを取り組んでみる。

#1: SPIRAL ROSETTES

コード(Emacs)

Python 3

```#!/usr/bin/env python3
import turtle

t = turtle.Pen()
t.speed(0)

t.penup()
turtle.bgcolor('black')
sides = int(turtle.numinput(
'Number of sides',
'How many sides in your spiral of spirals (2-6)?', 6, 2, 6))
number_of_circles = int(turtle.numinput(
'Number of circles', 'How many circles in your rosette?', 5))
colors = ['red', 'yellow', 'blue', 'green', 'purple', 'orange']

for m in range(100):
t.forward(m * 4)
position = t.position()
t.pendown()
t.width(m / 10)
for n in range(number_of_circles):
t.pencolor(colors[n % number_of_circles])
t.circle(int(m / number_of_circles))
t.right(360 / number_of_circles)
t.penup()
t.setx(position[0])
t.sety(position[1])
t.left(360 / sides + 2)

print('done')
input()
```

```\$ ./sample1.py
done
q
\$
```