Last active
January 2, 2020 08:33
-
-
Save darcyclark/32b28e3338ddfaa2895f54cf9363940a to your computer and use it in GitHub Desktop.
a little Python ditty to render animated New Year's wishes - using wasabi2d game framework [https://github.com/lordmauve/wasabi2d]
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
import math | |
from wasabi2d import Scene, run, event | |
from random import uniform as fraction | |
from random import randint as integer | |
from random import choice | |
scene = Scene() | |
scene.background = 'black' | |
screen = scene.layers[0] | |
screen.set_effect('bloom', radius=50, intensity=0.9) | |
items = [] | |
words = [ '2020', 'Happy', 'New Year' ] | |
W = scene.width | |
H = scene.height | |
@event | |
def on_mouse_move(pos, rel): | |
dx, dy = rel | |
r = math.sqrt( (dx**2)+(dy**2) ) | |
pos=(integer(0, W), integer(0, H)) | |
c = screen.add_circle( radius=r, pos=pos, color=random_color() ) | |
items.append(c) | |
l = screen.add_label(choice(words), align='center', fontsize=integer(0, 144), color=random_color(), pos=(integer(0, W), integer(0, H)) ) | |
items.append(l) | |
@event | |
def update(dt): | |
all_items = items[:] | |
items[:] = [ i for i in items if i.scale > 0.1 ] | |
for i in all_items: | |
if i not in items: | |
i.delete() | |
for item in items: | |
item.scale = item.scale * 0.9 # shrink | |
item.y = item.y * 1.04 # fall | |
item.x = item.x + integer(-3, 3) # jitter | |
def random_color(): | |
return ( fraction(0,1), fraction(0,1), fraction(0,1), fraction(0,1) ) | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍