レーダー

レーダー

なんとなく思いついて作成しました。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import pygame
import math

def main():
	pygame.init()
	pygame.display.set_mode((120, 120), 0, 32)
	screen = pygame.display.get_surface()
	
	timer = 0
	while True:
		for e in pygame.event.get():
			if e.type is pygame.QUIT :
				sys.exit()
		timer += 2
		if timer >= 360:
			timer -= 360
		drawMeter(screen, 40, 40, 10, timer)
		drawMeter(screen, 80, 40, 20, timer)
		drawMeter(screen, 60, 60, 50, timer)
		drawMeter(screen, 30, 70, 15, timer)
		drawMeter(screen, 70, 80, 15, timer)
		
		pygame.display.update()
		pygame.time.wait(10)
		screen.fill((0, 0, 0, 0))
		
def drawMeter(screen, x, y, r, timer):
	radius = r - 2
	dx = x + radius * math.cos(math.radians(timer))
	dy = y + radius * math.sin(math.radians(timer))
	pygame.draw.circle(screen, (0, 255, 0), (x, y), r, 1)
	for i in range(1, 20):
		dx = x + radius * math.cos(math.radians(timer-i))
		dy = y + radius * math.sin(math.radians(timer-i))
		pygame.draw.aaline(screen, (255/i, 0, 0), (x, y), (dx, dy))

if __name__ == "__main__":
	main()