fork(10) download
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import pygame
  4. from pygame.locals import *
  5. import sys
  6.  
  7. SCR = (640, 480)
  8.  
  9. pygame.init()
  10. screen = pygame.display.set_mode(SCR)
  11. pygame.display.set_caption(u"水面波紋")
  12.  
  13. clock = pygame.time.Clock()
  14.  
  15. animecycle = 3
  16. frame = 0
  17. x, y, z = 0, 0, 0
  18.  
  19. """任意に指定できる数値"""
  20. max_radius = 50 #描画する円の最大径
  21. vestige = 5 #同じ径の円を何回描画するか
  22. magnification = 3 #径を何倍にして描写するか
  23. """
  24. max_circles = 7, vestige = 3の時の挙動
  25. 描画パターン番号 1 2 3 4 5 6 7 8 9 10 11
  26. 各番号の描画円数 1 1 2 2 3 3 3 2 2 1 1
  27.   peak↑ ↑peak_end = max_radius
  28. 描画最小円半径  1 2 1 2 1 2 3 4 5 6 7
  29. """
  30.  
  31. max_time = vestige * 3 + max_radius - 3 #一つの波紋を構成する描画パターン数
  32. max_frame = max_time * animecycle #波紋を描き終えた時のフレーム
  33. peak = vestige * 2 - 1 #描画円数が初めて最高値になるパターン番号
  34.  
  35. while True:
  36. clock.tick(60)
  37. screen.fill((100,100,200))
  38.  
  39. frame += 1
  40. if frame > max_frame:
  41. frame = 1
  42. pattern = frame / animecycle #描画パターン番号
  43.  
  44. """描画円数を求める"""
  45. if pattern <= peak:
  46. draw_times = pattern / 2 #各番号の描画円数
  47. if pattern % 2 != 0:
  48. draw_times += 1
  49. if pattern > peak:
  50. if pattern <= max_radius:
  51. pass
  52. if pattern > max_radius:
  53. draw_times = vestige - (pattern - max_radius) / 2
  54. if (pattern - max_radius) % 2 != 0:
  55. draw_times -= 1
  56.  
  57. """描画最小円半径を求める"""
  58. if pattern < peak:
  59. radius = 1
  60. if pattern % 2 == 0:
  61. radius += 1
  62. if pattern >= peak:
  63. radius = pattern - peak + 1
  64. radius *= magnification
  65.  
  66. for i in range(draw_times):
  67. pygame.draw.circle(screen, (150,150,255), (320,240), radius, 1)
  68. radius += 2 * magnification
  69.  
  70. pygame.display.update()
  71. for event in pygame.event.get():
  72. if event.type == QUIT:
  73. pygame.quit()
  74. sys.exit()
  75.  
Runtime error #stdin #stdout #stderr 0.02s 44680KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "<builtin>/app_main.py", line 75, in run_toplevel
  File "prog.py", line 3, in <module>
    import pygame
ImportError: No module named pygame