Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #By Mr.A AKA A-MAN (c)2012-2013
- #All rights reserved
- #The A-Wave Simulator
- from pygame.locals import *
- import time, math, sys
- #Wave propertiess:
- AMPLITUDE = 130
- FREQUENCY = 2
- WAVELENGTH= 114
- #end
- WAVEVELOCITY = FREQUENCY * WAVELENGTH
- FPS = 30
- FPS_CLOCK = pygame.time.Clock()
- pygame.init()
- SCREEN = pygame.display.set_mode((1024, 768), pygame.FULLSCREEN)
- pygame.display.set_caption("The A-Wave simulator")
- FONT = pygame.font.SysFont(None, 20, False, False)
- VTEXT= FONT.render("Wave velocity (px/s): ", True, (0, 255, 0))
- VTEXTbdy = VTEXT.get_rect()
- VTEXTbdy.left = SCREEN.get_rect().left + 20
- VTEXTbdy.bottom=SCREEN.get_rect().bottom - 20
- FTEXT= FONT.render("Wave Frequency (s^-1): ", True, (0, 255, 0))
- FTEXTbdy = FTEXT.get_rect()
- FTEXTbdy.left = SCREEN.get_rect().left + 20
- FTEXTbdy.bottom=SCREEN.get_rect().bottom - 40
- WTEXT= FONT.render("Wave Length (px): ", True, (0, 255, 0))
- WTEXTbdy = WTEXT.get_rect()
- WTEXTbdy.left = SCREEN.get_rect().left + 20
- WTEXTbdy.bottom=SCREEN.get_rect().bottom - 60
- ATEXT= FONT.render("Max. Amplitude (px): ", True, (0, 255, 0))
- ATEXTbdy = ATEXT.get_rect()
- ATEXTbdy.left = SCREEN.get_rect().left + 20
- ATEXTbdy.bottom=SCREEN.get_rect().bottom - 80
- PXTEXT= FONT.render("1 cm ~= 38 px", True, (0, 255, 0))
- PXTEXTbdy = PXTEXT.get_rect()
- PXTEXTbdy.right = SCREEN.get_rect().right - 20
- PXTEXTbdy.bottom=SCREEN.get_rect().bottom - 20
- STARTINGPOS = (SCREEN.get_rect().right - 10, SCREEN.get_rect().centery)
- POINTS = []
- SCREEN.fill((0, 0, 0))
- FREQ = int(float(FPS) / float(FREQUENCY))
- while True:
- for a in range(FREQ):
- V= FONT.render(str(WAVEVELOCITY), True, (255, 255, 255))
- Vbdy = V.get_rect()
- Vbdy.left = VTEXTbdy.right + 30
- Vbdy.centery=VTEXTbdy.centery
- A= FONT.render(str(AMPLITUDE), True, (255, 255, 255))
- Abdy = A.get_rect()
- Abdy.left = ATEXTbdy.right + 30
- Abdy.centery=ATEXTbdy.centery
- F= FONT.render(str(FREQUENCY), True, (255, 255, 255))
- Fbdy = F.get_rect()
- Fbdy.left = FTEXTbdy.right + 12
- Fbdy.centery=FTEXTbdy.centery
- W= FONT.render(str(WAVELENGTH), True, (255, 255, 255))
- Wbdy = W.get_rect()
- Wbdy.left = WTEXTbdy.right + 50
- Wbdy.centery=WTEXTbdy.centery
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- if event.type == KEYDOWN :
- if event.key == K_q:
- AMPLITUDE += 10
- if event.key == K_a:
- AMPLITUDE -= 10
- if event.key == K_w:
- WAVELENGTH += 19
- WAVEVELOCITY = FREQUENCY * WAVELENGTH
- if event.key == K_s and WAVELENGTH > 19:
- WAVELENGTH -= 19
- WAVEVELOCITY = FREQUENCY * WAVELENGTH
- if event.key == K_e:
- FREQUENCY += 1
- WAVEVELOCITY = FREQUENCY * WAVELENGTH
- FREQ = int(float(FPS) / float(FREQUENCY))
- if event.key == K_d and FREQUENCY > 1 :
- FREQUENCY -= 1
- WAVEVELOCITY = FREQUENCY * WAVELENGTH
- FREQ = int(float(FPS) / float(FREQUENCY))
- posy= STARTINGPOS[1] - int(AMPLITUDE *(math.sin((2*math.pi) * float (float(a)/float(FREQ))) ) )
- posx= STARTINGPOS[0] - 10
- POINTS.append([posx, posy])
- pygame.draw.line(SCREEN, (255, 255, 255), (STARTINGPOS[0], posy), (STARTINGPOS[0], posy), 10)
- pygame.draw.line(SCREEN, (255, 255, 255), STARTINGPOS, (0, SCREEN.get_rect().centery), 2)
- if len(POINTS) > 1:
- pygame.draw.lines(SCREEN, (255, 0, 0), False, POINTS, 5)
- for b in range(len(POINTS)):
- #pygame.draw.line(SCREEN, (255, 0, 0), (b[0], b[1]), (b[0], b[1]), 5)
- POINTS[b][0] -= int(float(float(FREQUENCY) * float(WAVELENGTH))/float(FPS))
- TEMPVALUE = -1
- for b in range(len(POINTS)):
- TEMPVALUE += 1
- if POINTS[TEMPVALUE][0] < 0:
- del POINTS[TEMPVALUE]
- TEMPVALUE -= 1
- SCREEN.blit(VTEXT, VTEXTbdy)
- SCREEN.blit(FTEXT, FTEXTbdy)
- SCREEN.blit(ATEXT, ATEXTbdy)
- SCREEN.blit(WTEXT, WTEXTbdy)
- SCREEN.blit(PXTEXT, PXTEXTbdy)
- SCREEN.blit(V, Vbdy)
- SCREEN.blit(A, Abdy)
- SCREEN.blit(W, Wbdy)
- SCREEN.blit(F, Fbdy)
- pygame.display.update()
- FPS_CLOCK.tick(FPS)
- SCREEN.fill((0, 0, 0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement