Advertisement
eigenbom

Dr Who Tunnel

Oct 26th, 2016
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. # Dr Who
  2. # @eigenbom
  3. # Requires: pygame-zero
  4.  
  5. from math import sin, cos, pi
  6. from random import uniform as u
  7. import pygame
  8.  
  9. WIDTH, HEIGHT = 512, 512
  10. center = WIDTH/2, HEIGHT/2
  11. tunnel = center
  12. time = 0
  13.  
  14. sign = lambda x: 1 if x > 0 else -1 if x < 0 else 0
  15.  
  16. def update(dt):
  17.     global time, tunnel
  18.     time += dt
  19.                
  20. def draw():
  21.     global tunnel, center    
  22.    
  23.     # rotate and zoom
  24.     speedxor = 1.1 + 0.05 + 0.05*sin(time*0.33)
  25.     rotxor = 5.5 + 1.0*sin(time*0.33)
  26.     old_rect = screen.surface.get_rect()
  27.     new_surface = pygame.transform.rotozoom(screen.surface, rotxor,speedxor)
  28.     new_surface.set_alpha(200)
  29.     new_rect = new_surface.get_rect()
  30.     offx = old_rect.centerx - new_rect.width / 2
  31.     offy = old_rect.centery - new_rect.height / 2
  32.     screen.blit(new_surface, (offx,offy))
  33.    
  34.     # update tunnel center
  35.     tunnel = center[0] + 10*sin(time), center[1] + 10*cos(time)
  36.    
  37.     # colour
  38.     step = int(16 * (0.5 + 0.5*sin(time * 5)))
  39.     col = 128 + step*8    
  40.     screen.draw.filled_circle(tunnel, 10, (col, col, col))
  41.     screen.draw.filled_circle(tunnel, 5, (col/2,col/2,col/2))
  42.    
  43.     pulsor = sin(time*5) > 0.8
  44.     twistor = sin(time*88.01)    
  45.     for i in range(4):
  46.         x, y = 10*sin(-twistor*time*1.1 + i*pi/2), 10*cos(-twistor*time*1.1 + i*pi/2)
  47.         if pulsor:
  48.             colour = 0, 0, 0
  49.         else:
  50.             colour = [(255,0,0), (0, 255, 0), (0, 0, 255), (0, 128, 128)][i]
  51.         screen.draw.filled_circle((tunnel[0] + x, tunnel[1] + y), int(5 + 2*sin(time)), colour)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement