Skip to content

Instantly share code, notes, and snippets.

@Olikonsti
Created April 26, 2021 13:42
Show Gist options
  • Save Olikonsti/9fdf25602a9537ff9a66d8689cf1c8ba to your computer and use it in GitHub Desktop.
Save Olikonsti/9fdf25602a9537ff9a66d8689cf1c8ba to your computer and use it in GitHub Desktop.
from tkinter import *
import random
pixellist = []
class Pixel:
def __init__(self, app):
self.window = Tk()
self.window.config(bg=random.choice(["red", "green", "blue", "yellow", "lime", "cyan"]))
self.window.overrideredirect(True)
self.app = app
self.x = 10
self.y = 10
self.width = 100
self.height = 100
self.velx = random.randint(-5000, 5000)/200
self.vely = random.randint(-5000, 5000)/200
pixellist.append(self)
self.window.attributes("-topmost", True)
def update(self):
if self.x + self.x < 0 or self.x + self.velx + self.width > self.app.screenwidth:
self.velx = -self.velx
if self.y + self.y < 0 or self.y + self.vely + self.height > self.app.screenheight:
self.vely = -self.vely
self.x += self.velx
self.y += self.vely
self.window.geometry(f"{self.width}x{self.height}+{round(self.x)}+{round(self.y)}")
self.window.update()
class ScreenPixels:
def __init__(self):
root = Tk()
self.screenwidth = root.winfo_screenwidth()
self.screenheight = root.winfo_screenheight()
root.update()
root.destroy()
self.pixelamount = 10
for i in range(self.pixelamount):
Pixel(self)
while True:
for i in pixellist:
i.update()
ScreenPixels()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment