Skip to content

Instantly share code, notes, and snippets.

@m-doescode
Last active October 19, 2023 19:09
Show Gist options
  • Select an option

  • Save m-doescode/2b5eb193e571193d7d2c884d2f57ce53 to your computer and use it in GitHub Desktop.

Select an option

Save m-doescode/2b5eb193e571193d7d2c884d2f57ce53 to your computer and use it in GitHub Desktop.
Title
import pygame, sys
from pygame.locals import *
from time import sleep
from math import floor
import colorsys
sx = floor(500 / 2 - 50) - 100
sy = floor(500 / 2 - 50) - 200
dx = 1
dy = 1
hue = 0
def update_position_and_color():
global sx, sy, dx, dy, hue
hue = (hue + 1/255) % 1 # How quickly the hue changes
sx += dx * 4 # How fast it goes sideways
sy += dy * 5 # How fast it goes vertically
if sx > (500 - 50 * 1.5):
dx = -1
elif sx < (- 50 / 2):
dx = 1
if sy > (500 - 50 * 1.5):
dy = -1
elif sy < (- 50 / 2):
dy = 1
def main():
pygame.init()
DISPLAY=pygame.display.set_mode((500,500),0,32)
WHITE=(255,255,255)
BLUE=(0,0,255)
DISPLAY.fill(WHITE)
# pygame.event.clear()
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
# Shitty way of making this work but if it aint broke don't fix it.
sleep(0.02) # How fast each tick is
pygame.draw.rect(DISPLAY,[floor(x*255) for x in colorsys.hsv_to_rgb(hue, 1, 1)],(sx + 50 / 2,sy + 50 / 2,50,50)) # Fill
pygame.draw.rect(DISPLAY,(0,0,0),(sx + 50 / 2,sy + 50 / 2,50,50), 2) # Outline
update_position_and_color()
pygame.display.update()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment