import pygame, math

class Dash(object):
    def __init__(self, length, width, pos):
        self.length = length
        self.width = width
        self.heading = 0
        self.pos = pos
        self.color = pygame.color.Color(0,255,0)
        
    def rotate(self, distance):
        self.heading += distance
        
    def draw(self, surface):
        start = (int(self.pos[0]), int(self.pos[1]))
        x_delta = self.length * math.cos(self.heading)
        y_delta = self.length * math.sin(self.heading)
        end = (int(self.pos[0] + x_delta), int(self.pos[1] + y_delta))
        pygame.draw.line(surface, self.color, start, end, self.width)
        
def leftRight(shape, size, speed):
    pygame.init()
    pygame.key.set_repeat(50, 50)
    screen = pygame.display.set_mode(size)
    running = True

    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    shape.rotate(-speed)
                elif event.key == pygame.K_RIGHT:
                    shape.rotate(speed)
                    
            screen.fill(pygame.color.Color(0, 0, 0))
            shape.draw(screen)
            pygame.display.flip()
                
    pygame.quit()
    
