以前、Basicで作成したプログラムを移植してみました。
Ubuntu 16.04
Python 2.7
pygame 1.9.3
<参考>
プチコン3号講座 100匹目の金魚
bg.png
Ubuntu 16.04
Python 2.7
pygame 1.9.3
<参考>
プチコン3号講座 100匹目の金魚
bg.png
#!/usr/bin/python # -*- coding: utf-8 -*- import pygame from pygame.locals import * import random import math pygame.init() window_size = (640, 480) clock = pygame.time.Clock() screen = pygame.display.set_mode(window_size) img_char = pygame.image.load('bg.png') spimg = [] ex = [] ey = [] er = [] es = [] et = [] def dataset(): for n in range(100): ex.append(random.randrange(0, 640)) ey.append(random.randrange(0, 480)) er.append(random.randrange(0, 360)) es.append(random.randrange(0, 10)+10) et.append(30) def move(n): ex[n]=ex[n]+math.sin(math.radians(er[n]))*es[n] ey[n]=ey[n]-math.cos(math.radians(er[n]))*es[n] write(n) def turn(n): er[n]=er[n]+et[n] if er[n]>360: er[n] -= 360 if er[n]<0: er[n] += 360 write(n) def write(n): spwrite(random.randrange(0, 2)+12,ex[n],ey[n],270-er[n],2) def spset(): for y in range(10): for x in range(10): temp = pygame.Surface((16, 16), pygame.SRCALPHA) temp.blit(img_char, (0, 0), (x * 16, y * 16, 16, 16)) spimg.append(temp) def spwrite(cn,x,y,angle,scale): temp = pygame.transform.rotozoom(spimg[cn], angle,scale) screen.blit(temp, (x, y)) def main(): prg = "MMMMMMMMMMMT" prgn = 0 spset() dataset() bg_color = (0, 0, 0) end_game = False while not end_game: for event in pygame.event.get(): if event.type == pygame.QUIT: end_game = True screen.fill(bg_color) p=prg[prgn] for n in range(100): if p=="M": move(n) if p=="T": turn(n) prgn += 1 if prgn>11: prgn=0 pygame.display.flip() clock.tick(15) pygame.quit() quit() main()