プログラミング言語「Python」で制作 Part98 | Photoshop CC Tutorials

今回はプログラミング言語の「Python」を使って作成しました。

 

sin波を描画するプログラムです。

 

■ プログラム

import sys
from math import sin, cos, radians
import pygame
from pygame.locals import QUIT

pygame.init()
SURFACE = pygame.display.set_mode((600, 600))
FPSCLOCK = pygame.time.Clock()

def main():
    """ メインルーチン """
    theta = 0

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        SURFACE.fill((0, 0, 0))

        theta += 5

        points = []
        for index in range(0, 600):
            points.append((index, -sin(radians(theta+index)) * 300 + 300))

        pygame.draw.aalines(SURFACE, (0, 255, 0), False, points)

        pygame.display.update()
        FPSCLOCK.tick(30)

if __name__ == '__main__':
    main()

 

■ 参考書

「Pythonゲームプログラミング 知っておきたい数学と物理の基本」

 

■ ゲーム用ライブラリ

「Pygame」

 

■ プログラミング言語