2018年1月29日月曜日

開発環境

Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming (Bryson Payne(著)、No Starch Press)のChapter 5.(Conditions (What If?))、PROGRAMMING CHALLENGES、#1: COLORFUL ROSETTES AND SPIRALSを取り組んでみる。

#1: COLORFUL ROSETTES AND SPIRALS

コード(Emacs)

Python 3

#!/usr/bin/env python3
import turtle

t = turtle.Pen()
t.speed(0)
sides = int(turtle.numinput(
    'Number of sides',
    'How many sides in your spiral?', 4))
colors = ['red', 'yellow', 'blue', 'orange',
          'green', 'purple', 'brown', 'white', 'gray', 'pink']

turtle.bgcolor('black')
for m in range(5, 75):
    t.left(360 / sides + 5)
    t.width(m // 25 + 1)
    t.penup()
    t.forward(m * 4)
    t.pendown()
    if m % 2 == 0:
        for n in range(sides):
            t.pencolor(colors[n % sides])
            t.circle(m / 3)
            t.right(360 / sides)
    else:
        for n in range(sides):
            t.pencolor(colors[n % sides])
            t.forward(m)
            t.right(360 / sides)

print('done')
input()

入出力結果(Terminal, Jupyter(IPython))

$ ./sample1.py
done
q
$ ./sample1.py
done
q
$ ./sample1.py
done
q
$ ./sample1.py
done
q
$ ./sample1.py
done
q
$ ./sample1.py
done
q
$ ./sample1.py
done
q
$ ./sample1.py
done
q
$ ./sample1.py
done
q
$ 

0 コメント:

コメントを投稿