Last active
July 29, 2024 19:23
-
-
Save villares/968c41e594db6b83172700dcf856a09b to your computer and use it in GitHub Desktop.
fading screensaver-like sketch show
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
""" | |
You'll need py5 and a use the run_sketch tool or Thonny + thonny-py5mode | |
to run this py5 "imported mode" style sketch. Learn more at py5coding.org | |
I will run on full screen. Click on screen and press ESC to exit. | |
Adjust speed by changing the time_per_image variable in milliseconds. | |
""" | |
time_per_image = 3000 # milliseconds | |
fade_time = 500 # actually fade in + fade out will be double this | |
last_image_time = 0 | |
seed = 0 | |
def setup(): | |
full_screen() # this is an option instead of size() | |
# size(400, 400) # test | |
def draw(): | |
global seed | |
global last_image_time | |
background(0) | |
### Your work goes here | |
random_seed(seed) | |
grid(width / 2, height / 2, height * 0.8) | |
### Transitions | |
time_past = millis() - last_image_time | |
# fade out | |
fade_out = time_per_image - time_past | |
if fade_out < fade_time: | |
fill(0, 255 - fade_out / fade_time * 255) | |
rect(0, 0, width, height) | |
# fade in | |
if time_past < fade_time: | |
fill(0, 255 - time_past / fade_time * 255) | |
rect(0, 0, width, height) | |
if time_past > time_per_image: | |
seed = seed + 1 | |
last_image_time = millis() | |
def grid(gx, gy, gw): | |
color_mode(HSB) | |
no_stroke() | |
n = 4 | |
cw = gw / n | |
for i in range(n): | |
cx = i * cw + cw / 2 + gx - gw / 2 | |
for j in range(n): | |
cy = j * cw + cw / 2 + gy - gw / 2 | |
if random_int(1, 3) == 1 and cw > 50: | |
grid(cx, cy, cw) | |
else: | |
# diâmeto baseado na soma da linha coluna | |
d = random(10, cw * 2) | |
# matiz baseado no produto da linha e coluna | |
h = 10 + random_choice(((i * j), (i + j))) * 20 | |
c = color(h, 255, 200, 200) | |
fill(c) | |
# desenho do elemento em x, y | |
circle(cx, cy, d) |
Author
villares
commented
Jul 29, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment