開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Python 3.5 (プログラミング言語)
Python for Kids: A Playful Introduction to Programming (Jason R. Briggs (著) 、No Starch Press)のPart Ⅰ.(Learning to Program)、Chapter 12.(Using tkinter for Better Graphics)、Programming Puzzles #2: The Moving Triangle(No. 3603)を解いてみる。
Programming Puzzles #2: The Moving Triangle(No. 3603)
コード(Emacs)
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import time
import tkinter
app = tkinter.Tk()
canvas = tkinter.Canvas(app, width=400, height=200)
canvas.pack()
canvas.create_polygon(10, 10, 10, 60, 50, 35)
for x in range(0, 60):
canvas.move(1, 5, 0)
app.update()
time.sleep(0.05)
for x in range(0, 30):
canvas.move(1, 0, 5)
app.update()
time.sleep(0.05)
for x in range(0, 60):
canvas.move(1, -5, 0)
app.update()
time.sleep(0.05)
for x in range(0, 30):
canvas.move(1, 0, -5)
app.update()
time.sleep(0.05)
def app_move(c, x, y):
for a in range(c):
canvas.move(1, x, y)
app.update()
time.sleep(0.05)
for c, x, y in [(60, 5, 0), (30, 0, 5), (60, -5, 0), (30, 0, -5)]:
app_move(c, x, y)
入出力結果(Terminal, IPython)
$ ./sample2.py $
0 コメント:
コメントを投稿