
# sineRects.py
# Draw a sine curve using small rectangles


import pygame, sys, math   
from pygame.locals import *
           
BLACK = (   0,   0,   0)
WHITE = ( 255, 255, 255)
              
                   
pygame.init()
screen = pygame.display.set_mode([640,480])
screen.fill(WHITE)
pygame.display.set_caption("Sine Curve Drawn with Rectangles")

for x in range(0, 640):                                   
    y = int(math.sin(x/640.0 * 4*math.pi) * 200 + 240)  # sine curve formula
    
    # draw using small rectangles
    pygame.draw.rect(screen, BLACK, (x, y, 1, 1), 1)     
           # (x,y) is the location of each rectangle; (width,height) == 1


clock = pygame.time.Clock()

running = True
while running:
    clock.tick(30)

    # handle events
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False

    # update game state (nothing yet)
    # redraw game
    pygame.display.update()

pygame.quit()
