Last active
October 19, 2023 19:09
-
-
Save m-doescode/2b5eb193e571193d7d2c884d2f57ce53 to your computer and use it in GitHub Desktop.
Title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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