Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Last active April 11, 2020 17:08
Show Gist options
  • Save tshirtman/1336333bbf32c18cda51ef704f572912 to your computer and use it in GitHub Desktop.
Save tshirtman/1336333bbf32c18cda51ef704f572912 to your computer and use it in GitHub Desktop.
from random import random, choice
from glob import glob
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.clock import Clock
from kivy.graphics import Rectangle
from kivy.uix.widget import Widget
from kivy.core.window import Window
IMAGES = glob('/usr/share/icons/oxygen/base/64x64/emoteemotes/*.png')
class Application(App):
def build(self):
self.root = root = Widget(size=Window.size)
self.setup_scene(root)
Clock.schedule_interval(self.update, 0)
return root
def setup_scene(self, root):
width, height = self.root.size
self.rectangles = []
with root.canvas:
for i in range(1000):
r = Rectangle(
pos=(width / 2 - 32, height / 2 - 32),
size=(64, 64),
source=choice(IMAGES)
)
self.rectangles.append(r)
def update(self, dt):
for r in self.rectangles:
width, height = r.size
x, y = r.pos
x = min(self.root.width - width, max(0, x + 10 * (random() - .5)))
y = min(self.root.height - height, max(0, y + 10 * (random() - .5)))
r.pos = x, y
if __name__ == "__main__":
Application().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment