title: pygame both audial and visual sine wave
body: <p>Here is a function from my program, it called when a key is pressed. What is supposed to happen is the key is pressed and a corresponding note is played, and a sine wave appears on the screen also. The sound plays fine, so I won't post any more code for the sound, but it is just the visual side of things that don't work, why won't this wave show?</p>
  
  <pre><code>WINDOWWIDTH = 640 # width of the program's window, in pixels
  WINDOWHEIGHT = 480 # height in pixels
  WIN_CENTERX = int(WINDOWWIDTH / 2) # the midpoint for the width of the window
  WIN_CENTERY = int(WINDOWHEIGHT / 2) # the midpoint for the height of the window
  DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
  fontObj = pygame.font.SysFont('freesansbold.ttf', 16)
  FPSCLOCK = pygame.time.Clock()
  
  # set up a bunch of constants
  BLUE       = (  0,   0, 255)
  WHITE      = (255, 255, 255)
  DARKRED    = (128,   0,   0)
  DARKBLUE   = (  0,   0, 128)
  RED        = (255,   0,   0)
  GREEN      = (  0, 255,   0)
  DARKGREEN  = (  0, 128,   0)
  YELLOW     = (255, 255,   0)
  DARKYELLOW = (128, 128,   0)
  BLACK      = (  0,   0,   0)
  
  BGCOLOR = WHITE
  
  FPS = 160 # frames per second to run at
  
  pause = False
  
  
  # making text Surface and Rect objects for various labels
  sinLabelSurf = fontObj.render('sine', True, RED, BGCOLOR)
  squareLabelSurf = fontObj.render('square', True, BLUE, BGCOLOR)
  
  sinLabelRect = sinLabelSurf.get_rect()
  squareLabelRect = squareLabelSurf.get_rect()
  
  def MakeSineWave(freq=1000):
      #### visual part ####
      xPos = 0
      step = 0
      AMPLITUDE = 80 # how many pixels tall the waves with rise/fall.
      posRecord = {'sin': [], 'line': []}
  
      yPos = -1 * math.sin(step) * AMPLITUDE
      posRecord['sin'].append((int(xPos), int(yPos) + WIN_CENTERY))
  
      # draw the sine ball and label
      pygame.draw.circle(DISPLAYSURF, DARKRED, (int(xPos), int(yPos) + WIN_CENTERY), 10)
      sinLabelRect.center = (int(xPos), int(yPos) + WIN_CENTERY + 20)
      DISPLAYSURF.blit(sinLabelSurf, sinLabelRect)
  
      # draw the waves from the previously recorded ball positions
      for x, y in posRecord['sin']:
          pygame.draw.circle(DISPLAYSURF, DARKRED, (x, y), 4)
  
      # draw the border
      pygame.draw.rect(DISPLAYSURF, BLACK, (0, 0, WINDOWWIDTH, WINDOWHEIGHT), 1)
  
      pygame.display.update()
      FPSCLOCK.tick(FPS)
  
      if not pause:
          xPos += 0.5
          if xPos &gt; WINDOWWIDTH:
              xPos = 0
              posRecord = {'sin': []}
              step = 0
          else:
              step += 0.008
  
      #### audial part ####
      return MakeSound(SineWave(freq))
  </code></pre>