開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
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、#2: A SPIRAL OF FAMILY SPIRALSを取り組んでみる。
#2: A SPIRAL OF FAMILY SPIRALS
コード(Emacs)
Python 3
#!/usr/bin/env python3 import turtle colors = ['red', 'yellow', 'blue', 'orange', 'green', 'purple', 'brown', 'white', 'gray', 'pink'] t = turtle.Pen() t.speed(0) turtle.bgcolor('black') family = [] name = turtle.textinput( 'My family', 'Enter a name, or just hit [Enter] to end:') while name != '': family.append(name) name = turtle.textinput( 'My family', 'Enter a name, or just hit [Enter] to end:') for m in range(100): t.forward(m * 4) position = t.position() heading = t.heading() t.width(m / 10) for x in range(len(family)): t.pencolor(colors[x % len(family)]) t.pendown() t.write(family[x % len(family)], font=( 'Arial', int((m + 4) / 4), 'bold')) t.penup() t.forward(m) t.setx(position[0]) t.sety(position[1]) t.setheading(heading) t.left(360 / len(family) + 2) print('done') input()
入出力結果(Terminal, Jupyter(IPython))
$ ./sample2.py done q $ ./sample2.py done q $ ./sample2.py done q $ ./sample2.py done q $ ./sample2.py done q $ ./sample2.py done q $ ./sample2.py done q $ ./sample2.py done q $
0 コメント:
コメントを投稿