Advertisement
Mr-A

A-Wave Simulator

Mar 24th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.58 KB | None | 0 0
  1. #By Mr.A AKA A-MAN (c)2012-2013
  2. #All rights reserved
  3. #The A-Wave Simulator
  4.  
  5.  
  6. from pygame.locals import *
  7. import time, math, sys
  8.  
  9. #Wave propertiess:
  10. AMPLITUDE = 130
  11. FREQUENCY = 2
  12. WAVELENGTH= 114
  13. #end
  14.  
  15. WAVEVELOCITY = FREQUENCY * WAVELENGTH
  16.  
  17. FPS = 30
  18. FPS_CLOCK = pygame.time.Clock()
  19.  
  20. pygame.init()
  21.  
  22. SCREEN = pygame.display.set_mode((1024, 768), pygame.FULLSCREEN)
  23. pygame.display.set_caption("The A-Wave simulator")
  24.  
  25. FONT = pygame.font.SysFont(None, 20, False, False)
  26. VTEXT= FONT.render("Wave velocity (px/s): ", True, (0, 255, 0))
  27. VTEXTbdy = VTEXT.get_rect()
  28. VTEXTbdy.left = SCREEN.get_rect().left + 20
  29. VTEXTbdy.bottom=SCREEN.get_rect().bottom - 20
  30.  
  31. FTEXT= FONT.render("Wave Frequency (s^-1): ", True, (0, 255, 0))
  32. FTEXTbdy = FTEXT.get_rect()
  33. FTEXTbdy.left = SCREEN.get_rect().left + 20
  34. FTEXTbdy.bottom=SCREEN.get_rect().bottom - 40
  35.  
  36. WTEXT= FONT.render("Wave Length (px): ", True, (0, 255, 0))
  37. WTEXTbdy = WTEXT.get_rect()
  38. WTEXTbdy.left = SCREEN.get_rect().left + 20
  39. WTEXTbdy.bottom=SCREEN.get_rect().bottom - 60
  40.  
  41. ATEXT= FONT.render("Max. Amplitude (px): ", True, (0, 255, 0))
  42. ATEXTbdy = ATEXT.get_rect()
  43. ATEXTbdy.left = SCREEN.get_rect().left + 20
  44. ATEXTbdy.bottom=SCREEN.get_rect().bottom - 80
  45.  
  46. PXTEXT= FONT.render("1 cm ~= 38 px", True, (0, 255, 0))
  47. PXTEXTbdy = PXTEXT.get_rect()
  48. PXTEXTbdy.right = SCREEN.get_rect().right - 20
  49. PXTEXTbdy.bottom=SCREEN.get_rect().bottom - 20
  50.  
  51.  
  52. STARTINGPOS = (SCREEN.get_rect().right - 10, SCREEN.get_rect().centery)
  53. POINTS      = []
  54.  
  55.  
  56.  
  57. SCREEN.fill((0, 0, 0))
  58.  
  59. FREQ = int(float(FPS) / float(FREQUENCY))
  60.  
  61. while True:
  62.     for a in range(FREQ):
  63.         V= FONT.render(str(WAVEVELOCITY), True, (255, 255, 255))
  64.         Vbdy = V.get_rect()
  65.         Vbdy.left = VTEXTbdy.right + 30
  66.         Vbdy.centery=VTEXTbdy.centery
  67.  
  68.         A= FONT.render(str(AMPLITUDE), True, (255, 255, 255))
  69.         Abdy = A.get_rect()
  70.         Abdy.left = ATEXTbdy.right + 30
  71.         Abdy.centery=ATEXTbdy.centery
  72.  
  73.         F= FONT.render(str(FREQUENCY), True, (255, 255, 255))
  74.         Fbdy = F.get_rect()
  75.         Fbdy.left = FTEXTbdy.right + 12
  76.         Fbdy.centery=FTEXTbdy.centery
  77.  
  78.         W= FONT.render(str(WAVELENGTH), True, (255, 255, 255))
  79.         Wbdy = W.get_rect()
  80.         Wbdy.left = WTEXTbdy.right + 50
  81.         Wbdy.centery=WTEXTbdy.centery
  82.         for event in pygame.event.get():
  83.             if event.type == QUIT:
  84.                 pygame.quit()
  85.                 sys.exit()
  86.             if event.type == KEYDOWN :
  87.                 if event.key == K_q:
  88.                     AMPLITUDE += 10
  89.                 if event.key == K_a:
  90.                     AMPLITUDE -= 10
  91.                 if event.key == K_w:
  92.                     WAVELENGTH += 19
  93.                     WAVEVELOCITY = FREQUENCY * WAVELENGTH
  94.                 if event.key == K_s and WAVELENGTH > 19:
  95.                     WAVELENGTH -= 19
  96.                     WAVEVELOCITY = FREQUENCY * WAVELENGTH
  97.                 if event.key == K_e:
  98.                     FREQUENCY += 1
  99.                     WAVEVELOCITY = FREQUENCY * WAVELENGTH
  100.                     FREQ = int(float(FPS) / float(FREQUENCY))
  101.                 if event.key == K_d and FREQUENCY > 1 :
  102.                     FREQUENCY -= 1
  103.                     WAVEVELOCITY = FREQUENCY * WAVELENGTH
  104.                     FREQ = int(float(FPS) / float(FREQUENCY))
  105.         posy= STARTINGPOS[1] - int(AMPLITUDE *(math.sin((2*math.pi) * float (float(a)/float(FREQ))) )  )
  106.         posx= STARTINGPOS[0] - 10
  107.  
  108.         POINTS.append([posx, posy])
  109.        
  110.         pygame.draw.line(SCREEN, (255, 255, 255), (STARTINGPOS[0], posy), (STARTINGPOS[0], posy), 10)
  111.         pygame.draw.line(SCREEN, (255, 255, 255), STARTINGPOS, (0, SCREEN.get_rect().centery), 2)
  112.         if len(POINTS) > 1:
  113.             pygame.draw.lines(SCREEN, (255, 0, 0), False, POINTS, 5)
  114.         for b in range(len(POINTS)):
  115.             #pygame.draw.line(SCREEN, (255, 0, 0), (b[0], b[1]), (b[0], b[1]), 5)
  116.            
  117.             POINTS[b][0] -= int(float(float(FREQUENCY) * float(WAVELENGTH))/float(FPS))
  118.         TEMPVALUE = -1
  119.         for b in range(len(POINTS)):
  120.             TEMPVALUE += 1
  121.             if POINTS[TEMPVALUE][0] < 0:
  122.                 del POINTS[TEMPVALUE]
  123.                 TEMPVALUE -= 1
  124.  
  125.         SCREEN.blit(VTEXT, VTEXTbdy)
  126.         SCREEN.blit(FTEXT, FTEXTbdy)
  127.         SCREEN.blit(ATEXT, ATEXTbdy)
  128.         SCREEN.blit(WTEXT, WTEXTbdy)
  129.         SCREEN.blit(PXTEXT, PXTEXTbdy)
  130.  
  131.         SCREEN.blit(V, Vbdy)
  132.         SCREEN.blit(A, Abdy)
  133.         SCREEN.blit(W, Wbdy)
  134.         SCREEN.blit(F, Fbdy)
  135.         pygame.display.update()
  136.         FPS_CLOCK.tick(FPS)
  137.         SCREEN.fill((0, 0, 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement