-
-
Save Djent-/8e9b0db9cb6101228d6a6c22730faccf to your computer and use it in GitHub Desktop.
Recreate Razer Synapse's Reactive Firefly mousepad effect with any mouse!
This file contains hidden or 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 colorsys | |
import time | |
from random import random | |
from openrazer.client import DeviceManager | |
from pynput import mouse | |
razer_device_manager = DeviceManager() | |
for device in razer_device_manager.devices: | |
if device.type == "mousemat": | |
firefly = device | |
break | |
else: | |
raise Exception("Could not find firefly!") | |
last_time = { | |
"color": time.time(), | |
"react": time.time() | |
} | |
def react(x, y, button=None, down=None): | |
global last_time | |
print(x, y, button, down) | |
this_time = time.time() | |
# Don't change color on button release | |
if (down or down == -1) and this_time - last_time["color"] > 0.1: | |
color = list(map(lambda x: int(x * 255), colorsys.hsv_to_rgb(random(), 1, 1))) | |
firefly.fx.reactive(color[0], color[1], color[2], 1) | |
last_time["color"] = this_time | |
if this_time - last_time["react"] > 0.05: | |
firefly.trigger_reactive() | |
last_time["react"] = this_time | |
while True: | |
try: | |
with mouse.Listener(on_click=react, on_move=react, on_scroll=react) as mouse_listener: | |
mouse_listener.join() | |
except Exception as e: | |
print(e) |
This file contains hidden or 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 colorsys | |
from random import random | |
from openrazer.client import DeviceManager | |
from pynput import mouse | |
razer_device_manager = DeviceManager() | |
for device in razer_device_manager.devices: | |
if device.type == "mousemat": | |
firefly = device | |
break | |
else: | |
raise Exception("Could not find firefly!") | |
def react(x, y, button, down): | |
#print(x, y, button, down) | |
# Don't change color on button release | |
if down: | |
color = list(map(lambda x: int(x * 255), colorsys.hsv_to_rgb(random(), 1, 1))) | |
firefly.fx.reactive(color[0], color[1], color[2], 1) | |
firefly.trigger_reactive() | |
while True: | |
try: | |
with mouse.Listener( | |
on_click=react) as mouse_listener: | |
mouse_listener.join() | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment