Python Pygame script to create lines screensaver effect.

Content not available.
Please allow cookies by clicking Accept on the banner

import pygame
import sys
from random import randint

# © 2019 TheFlyingKeyboard and released under MIT License
# theflyingkeyboard.net

screenXSize = 1920
screenYSize = 1080

backgroundColor = (0, 0, 0)

pygame.init()
screen = pygame.display.set_mode((screenXSize, screenYSize))
screen.fill(backgroundColor)

clock = pygame.time.Clock()

fps = 3

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                pygame.quit()
                sys.exit()
            if event.key == pygame.K_r:
                screen.fill(backgroundColor)
            if event.key == pygame.K_q:
                fps += 1
            if event.key == pygame.K_a:
                fps -= 1
                if fps == 0:
                    fps = 1

    pygame.display.set_caption("Lines " + str(fps) + "fps")

    pygame.draw.line(screen, (randint(0, 255), randint(0, 255), randint(0, 255)),
                       (randint(0, screenXSize), randint(0, screenYSize)),
                       (randint(0, screenXSize), randint(0, screenYSize)), 7)

    pygame.display.update()

    msElapsed = clock.tick(fps)

 

 



Python Pygame Lines Screensaver Effect
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. You can read more about it the Cookies&Privacy Policy Section Above. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this. You can read more about it the Cookies&Privacy Policy Section.

Close