Created
April 26, 2021 13:45
-
-
Save Olikonsti/3cf47df76e076b281b08cf35d172c155 to your computer and use it in GitHub Desktop.
ScreenPixels Gravity
This file contains 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
from tkinter import * | |
import random | |
import pygame | |
pixellist = [] | |
updatelist = [] | |
class Pixel: | |
def __init__(self, app): | |
self.window = Tk() | |
self.window.overrideredirect(True) | |
self.window.config(bg=random.choice(["red", "green", "blue", "yellow", "orange", "cyan", "lime"])) | |
self.app = app | |
self.state = "down" | |
self.x = 100 | |
self.y = 100 | |
self.width = 100 | |
self.height = 100 | |
self.velx = random.randint(-5000, 5000)/100 | |
self.vely = random.randint(-5000, 5000)/200 | |
pixellist.append(self) | |
updatelist.append(self) | |
self.window.attributes("-topmost", True) | |
def update(self): | |
self.vely += 5 | |
if self.state == "down": | |
self.width -= 5 | |
self.height -= 5 | |
if self.width < 15: | |
self.state = "up" | |
if self.state == "up": | |
self.width += 5 | |
self.height += 5 | |
if self.width > 150: | |
self.state = "down" | |
if self.x + self.velx < 0 or self.x + self.velx + self.width > self.app.screenwidth: | |
self.velx = -self.velx | |
if self.y + self.vely < 0: | |
self.vely = -self.vely | |
if self.y + self.vely + self.height > self.app.screenheight: | |
self.vely = -self.vely | |
self.vely += 14 | |
self.velx = self.velx/1.2 | |
if self.vely < 5 and self.vely > -5: | |
self.vely = 0 | |
self.velx = 0 | |
self.y = self.app.screenheight - self.height | |
pixellist.remove(self) | |
self.x += self.velx | |
self.y += self.vely | |
try: | |
self.window.geometry(f"{self.width}x{self.height}+{round(self.x)}+{round(self.y)}") | |
except: | |
pass | |
def updatewin(self): | |
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.clock = pygame.time.Clock() | |
self.tick = 0 | |
self.pixelamount = 1 | |
for i in range(self.pixelamount): | |
pixel = Pixel(self) | |
while True: | |
self.clock.tick(100) | |
self.tick += 1 | |
if self.tick % 30 == 0: | |
print(f"Active Particles: {len(pixellist)}\nAll Particles: {len(updatelist)}") | |
pixel = Pixel(self) | |
for i in pixellist: | |
i.update() | |
for i in updatelist: | |
i.updatewin() | |
ScreenPixels() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment