2018年2月8日木曜日

開発環境

Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming (Bryson Payne(著)、No Starch Press)のChapter 8.(Timers and Animation: What Would Disney Do?)、PROGRAMMING CHALLENGES、#1: A COLOR-CHANGING DOTを取り組んでみる。

#1: A COLOR-CHANGING DOT

コード(Emacs)

Python 3

#!/usr/bin/env python3
import pygame
import random
import time

# RED = (255, 0, 0)
# GREEN = (0, 255, 0)
# BLUE = (0, 0, 255)
pygame.init()
screen = pygame.display.set_mode([800, 600])

keep_going = True
radius = 50
while keep_going:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keep_going = False
    COLOR = [random.randrange(256) for _ in range(3)]
    print(COLOR)
    pygame.draw.circle(screen, COLOR, (100, 100), radius)
    pygame.display.update()
    time.sleep(1)

pygame.quit()

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

$ ./sample1.py
[153, 86, 84]
[94, 27, 68]
[5, 87, 60]
[21, 12, 129]
[30, 146, 204]
[234, 212, 10]
[118, 5, 194]
[22, 75, 128]
[103, 234, 51]
[159, 217, 224]
[57, 140, 138]
[219, 170, 42]
[217, 147, 83]
[201, 24, 192]
[17, 174, 249]
[125, 94, 71]
[226, 85, 171]
[116, 168, 148]
[5, 223, 11]
[248, 149, 248]
[190, 27, 129]
$

0 コメント:

コメントを投稿