import pygame, random, math, time

students =["Eleni","Cosmin","Alexandros","Yasna","Philippos",\
           "Said Rahim","Athanasia","Said Azim","Rafi","Nouroz Ali",\
           "Eleftheria Sofia","Stefanos","Pooya","Rashed","Sara","Marina",\
           "Despina","Layla","Ahlam","Maher","Michalis","Ayman",\
           "Nazdar","Nizar","Maya","Imran","Bajwa","Amir",\
           "Sorren","Mahdi","Safi"]

instructors = ("Eva","George", "Michalis")

support = ("Crysanthe","Despina","Laura","Thanassis","www.ellak.gr") 

def radians(degrees):
    return degrees*math.pi/180

class Particle:
    def __init__(self, x, y, radius, speed, angle, colour, surface):
        self.x = x
        self.y = y
        self.speed = speed
        self.angle = angle
        self.radius = 3
        self.surface = surface
        self.colour = colour
        self.rect = pygame.draw.circle(surface,(255,255,0),
                           (int(round(x,0)),
                            int(round(y,0))),
                           self.radius)
    def move(self):
        """ Update speed and position based on speed, angle """
        # for constant change in position values.
        self.x += math.sin(self.angle) * self.speed
        self.y -= math.cos(self.angle) * self.speed
        # pygame.rect likes int arguments for x and y
        self.rect.x = int(round(self.x))
        self.rect.y = int(round(self.y))

    def draw(self):
        """ Draw the particle on screen"""
        pygame.draw.circle(self.surface,self.colour,self.rect.center,self.radius)

    def bounce(self):
        """ Tests whether a particle has hit the boundary of the environment """

        if self.x > self.surface.get_width() - self.radius: # right
            self.x = 2*(self.surface.get_width() - self.radius) - self.x
            self.angle = - self.angle

        elif self.x < self.radius: # left
            self.x = 2*self.radius - self.x
            self.angle = - self.angle            

        if self.y > self.surface.get_height() - self.radius: # bottom
            self.y = 2*(self.surface.get_height() - self.radius) - self.y
            self.angle = math.pi - self.angle

        elif self.y < self.radius: # top
            self.y = 2*self.radius - self.y
            self.angle = math.pi - self.angle

def main():
    xmax = 1024    #width of window
    ymax = 768     #height of window
    white = (255, 255, 255)
    black = (0,0,0)
    grey = (128,128,128)

    pygame.init()
    screen = pygame.display.set_mode((xmax,ymax))
    pygame.display.set_caption("Certificate of Python Course - May 2017")
    # initialize font; must be called after 'pygame.init()' to avoid 'Font not Initialized' error
    myfont = pygame.font.SysFont("monospace", 65)
    clock = pygame.time.Clock()

    particles = []

    for i in range(2000):
        #if i % 2:
        #    colour = black
        #else:
            #colour = grey
        colour = random.sample(range(30,256), 3)
        # for readability
        x = random.randint(0, xmax)
        y = random.randint(0, ymax)
        speed = random.randint(0,20)*0.1
        angle = random.randint(0,360)
        radius = 3
        particles.append( Particle(x, y, radius, speed, angle, colour, screen) )

    done = False
    while not done:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
                break
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    done = True
                    break
        if done:
            break

        screen.fill(black)
        for p in particles:
            p.move()
            p.bounce()
            p.draw()
        

        # render text
        label0 = myfont.render("May 2017 - Python Class" , 1, (255,0,255))
        screen.blit(label0, (60, 60))
        z = int((time.clock()//3)%len(students))
        start = 20  + int((300 * time.clock()%900))
        label = myfont.render(students[z], 1, (255,255,255))
        screen.blit(label, (start, 180))
        label2 = myfont.render("learned to code in Python" , 1, (255,0,0))
        screen.blit(label2, (20, 240))
        label2a = myfont.render("with the support of" , 1, (0,100,255))
        screen.blit(label2a, (20, 360))
        label2b = myfont.render("Chrysanthe, Despina" , 1, (0,100,255))
        screen.blit(label2b, (20, 420))
        label2c = myfont.render("Laura, Thanassis" , 1, (0,100,255))
        screen.blit(label2c, (20, 480))
        label2d = myfont.render("and ellak.gr" , 1, (200,100,255))
        screen.blit(label2d, (20, 540))
        label3 = myfont.render("signed by the instructors:", 1, (128,255,50))
        screen.blit(label3, (10, 600))
        label4 = myfont.render("Eva, George and Michalis", 1, (255,0,255))
        screen.blit(label4, (40, 650))

        clock.tick(60)

        pygame.display.flip()
    pygame.quit()

if __name__ == "__main__":
    main()