Skip to content

Commit cfb170e

Browse files
Exagarm-hullgemini-code-assist[bot]
authored
Added DIGITALRAIN_INTENSITY setting to control digital rain density (#191)
* fix for clock.py display date-time overlapping * Added adjustable setting for density and frequency SUMMARY OF MODIFICATIONS AND CURRENT SCRIPT BEHAVIOR --------------------------------------------------- 1. NEW SETTING: DIGITALRAIN_INTENSITY - Added at the top of the script: DIGITALRAIN_INTENSITY = 5 - Range: 1 (sparse/light) → 9 (dense/heavy) - Purpose: Controls both the number of "digital rain" drops per spawn and the spawn frequency. 2. MODIFIED increase_population() - Original: def increase_population(): blue_pilled_population.append([randint(0, device.width), 0, gauss(1.2, 0.6)]) - Modified: def increase_population(): drops_per_tick = max(1, int(DIGITALRAIN_INTENSITY * 0.5)) for _ in range(drops_per_tick): blue_pilled_population.append([randint(0, device.width), 0, gauss(1.2, 0.6)]) - Effect: The number of drops added per spawn scales with intensity. - Intensity 1 → 1 drop per spawn - Intensity 9 → 4 drops per spawn (capped to prevent screen saturation) 3. NEW HELPER FUNCTION: should_spawn(clock) - Original spawn condition: if clock % 5 == 0 or clock % 3 == 0: increase_population() - Modified: def should_spawn(clock): interval = max(1, 10 - DIGITALRAIN_INTENSITY) return clock % interval == 0 ... if should_spawn(clock): increase_population() - Effect: Spawn frequency dynamically scales with intensity. - Intensity 1 → interval = 9 ticks (sparse rain) - Intensity 9 → interval = 1 tick (heavy rain) - Combined with drop-per-tick scaling, ensures heavy rain remains dynamic without filling the screen entirely. 4. OTHER CODE - All other original behavior preserved: - Color gradient in wrd_rgb is unchanged - Speed of each drop controlled by gauss(1.2, 0.6) - Maximum population still capped at device.width * 8 - Framerate regulated at 10 fps - Canvas rendering logic unchanged - KeyboardInterrupt handling preserved 5. HOW THE SCRIPT WORKS NOW - Loop increments clock each tick - On each tick: a) Render all current drops on the canvas with their colors b) Move each drop downward according to its speed c) Determine if new drops should spawn using should_spawn(clock) - If yes, spawn drops_per_tick new drops d) Trim blue_pilled_population if it exceeds max_population - Result: Digital rain density and intensity scale with the DIGITALRAIN_INTENSITY setting, giving smooth, adjustable visual effect without saturation or static appearance. 6. TUNABLE EFFECTS - Adjust DIGITALRAIN_INTENSITY (1–9) to control visual density and dynamic behavior: - 1 = very light rain - 5 = balanced medium rain - 9 = heavy rain, still dynamic, screen not static * Apply suggestion from @gemini-code-assist[bot] Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * corrected formatting on matrix_intensity.py code qa: commands[0]> flake8 ./examples/matrix_intensity.py:24:1: E302 expected 2 blank lines, found 1 ./examples/matrix_intensity.py:84:1: E305 expected 2 blank lines after class or function definition, found 1 ./examples/matrix_intensity.py:90:1: E265 block comment should start with '# ' ./examples/matrix_intensity.py:91:1: W391 blank line at end of file * Update matrix_intensity.py Added 'device.width -1' to enhance display effect of digital rain. Addressed and corrected the line spacing errors: qa: commands[0]> flake8 ./examples/matrix_intensity.py:24:1: E302 expected 2 blank lines, found 1 ./examples/matrix_intensity.py:84:1: E305 expected 2 blank lines after class or function definition, found 1 ./examples/matrix_intensity.py:90:1: E265 block comment should start with '# ' ./examples/matrix_intensity.py:91:1: W391 blank line at end of file * Fix QA transgressions --------- Co-authored-by: Richard Hull <rm_hull@yahoo.co.uk> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 2a9ed1e commit cfb170e

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

examples/matrix_intensity.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2014-19 Richard Hull and contributors
4+
# See LICENSE.rst for details.
5+
# PYTHON_ARGCOMPLETE_OK
6+
7+
"""
8+
The Matrix.
9+
10+
Adapted from:
11+
https://github.com/pimoroni/unicorn-hat-hd/blob/master/examples/matrix-hd.py
12+
"""
13+
14+
from random import randint, gauss, uniform
15+
from demo_opts import get_device
16+
from luma.core.render import canvas
17+
from luma.core.sprite_system import framerate_regulator
18+
19+
20+
# Digital rain intensity setting
21+
# 1 (sparse/light) → 9 (dense/heavy)
22+
23+
DIGITALRAIN_INTENSITY = 5
24+
25+
26+
def matrix(device):
27+
wrd_rgb = [
28+
(154, 173, 154),
29+
(0, 255, 0),
30+
(0, 235, 0),
31+
(0, 220, 0),
32+
(0, 185, 0),
33+
(0, 165, 0),
34+
(0, 128, 0),
35+
(0, 0, 0),
36+
(154, 173, 154),
37+
(0, 145, 0),
38+
(0, 125, 0),
39+
(0, 100, 0),
40+
(0, 80, 0),
41+
(0, 60, 0),
42+
(0, 40, 0),
43+
(0, 0, 0),
44+
]
45+
46+
clock = 0
47+
blue_pilled_population = []
48+
max_population = device.width * 8
49+
regulator = framerate_regulator(fps=10)
50+
51+
def increase_population():
52+
drops_per_tick = max(1, int(DIGITALRAIN_INTENSITY * 0.5))
53+
for _ in range(drops_per_tick):
54+
blue_pilled_population.append(
55+
[randint(0, device.width - 1), 0, gauss(1.2, 0.6)]
56+
)
57+
58+
def should_spawn(clock):
59+
interval = max(1, 10 - DIGITALRAIN_INTENSITY)
60+
return clock % interval == 0
61+
62+
while True:
63+
clock += 1
64+
with regulator:
65+
with canvas(device, dither=True) as draw:
66+
for person in blue_pilled_population:
67+
x, y, speed = person
68+
# Add subtle speed jitter
69+
speed += uniform(-0.05, 0.05)
70+
person[2] = speed
71+
72+
for rgb in wrd_rgb:
73+
if 0 <= y < device.height:
74+
# Add subtle brightness variation
75+
r, g, b = rgb
76+
multiplier = uniform(0.6, 1.2) # 60% → 120% of base green
77+
g = max(0, min(255, int(g * multiplier)))
78+
draw.point((x, y), fill=(r, g, b))
79+
y -= 1
80+
person[1] += speed
81+
82+
if should_spawn(clock):
83+
increase_population()
84+
85+
while len(blue_pilled_population) > max_population:
86+
blue_pilled_population.pop(0)
87+
88+
89+
if __name__ == "__main__":
90+
try:
91+
matrix(get_device())
92+
except KeyboardInterrupt:
93+
pass

0 commit comments

Comments
 (0)