full_screen = True window_size = (1024, 768) import sys, random, pygame from pygame.locals import * from math import * circles = ((0, 1),) circle_scale = 0.3 circle_radius = 8 n_grid = 3 grid_spacing = 0.2 grid_length = 0.05 grid_width = 2 fix_radius = 8 rotation_speed = pi/2 bg_color = (0, 0, 0) grid_color = (100, 100, 255) circle_color = (255, 255, 0) disapp_frames = 1 window_center = (window_size[0]/2.0, window_size[1]/2.0) window_scale = min(window_size)/2.0 def coord(real): """takes real coordinates, returns pixel coordinates""" return (int(round(real[0]*window_scale + window_center[0])),\ int(round(-real[1]*window_scale + window_center[1]))) g_cos, g_sin = 1, 0 def set_rotation(angle): """sets up rotation""" global g_cos, g_sin g_cos, g_sin = cos(angle), sin(angle) def rotate(point): """rotates a 3D point about the Z-axis by given angle set by set_rotation()""" return (g_cos*point[0] + g_sin*point[1], -g_sin*point[0] + g_cos*point[1]) # graphics initializations frames, show = 0, True try: pygame.init() if full_screen: surf = pygame.display.set_mode(window_size, HWSURFACE | FULLSCREEN | DOUBLEBUF) else: surf = pygame.display.set_mode(window_size) t0 = pygame.time.get_ticks() while True: for event in pygame.event.get(): if event.type in (QUIT, KEYDOWN): raise Exception() elif event.type == MOUSEBUTTONDOWN: frames, show = 0, False elif event.type == MOUSEBUTTONUP: frames, show = 0, True surf.fill(bg_color) t = (pygame.time.get_ticks() - t0)/1000.0 set_rotation(rotation_speed*t) for i in range(-n_grid, +n_grid + 1): for j in range(-n_grid, +n_grid + 1): center = (grid_spacing*i, grid_spacing*j) fr = rotate((center[0] - grid_length, center[1])) to = rotate((center[0] + grid_length, center[1])) pygame.draw.line(surf, grid_color, coord(fr), coord(to), grid_width) fr = rotate((center[0], center[1] - grid_length)) to = rotate((center[0], center[1] + grid_length)) pygame.draw.line(surf, grid_color, coord(fr), coord(to), grid_width) for circ in circles: c = (circle_scale*circ[0], circle_scale*circ[1]) if show: col = (150, 150, 0) pygame.draw.circle(surf, col, coord(c), circle_radius, 0) else: step = 150/disapp_frames lev = max(0, 150 - frames*step) col = (lev, lev, 0) if lev > 0: pygame.draw.circle(surf, col, coord(c), circle_radius, 0) pygame.draw.circle(surf, grid_color, coord((0, 0)), fix_radius) pygame.display.flip() frames += 1 finally: pygame.quit()