Skip to content

Instantly share code, notes, and snippets.

@loganintech
Created November 14, 2016 20:42
Show Gist options
  • Save loganintech/4cb8a19c11fcb6caca58be03d76518bb to your computer and use it in GitHub Desktop.
Save loganintech/4cb8a19c11fcb6caca58be03d76518bb to your computer and use it in GitHub Desktop.
Gets the track title of a spotify song and plays it on the keyboard in a way people can hopefully read.
----------------------------------------------------------------------------------
-------------------------------- Artemis LUA file --------------------------------
----------------------------------------------------------------------------------
-- This is a default script to be executed by Artemis.
-- You do not need to use this if you don't want to script. The default profiles
-- should provide you with a lot of functionality out of the box.
-- However, if you want to change the way profiles work, this is the ideal way
-- go about it.
-- For docs and examples, see wiki: https://github.com/SpoinkyNL/Artemis/wiki/LUA
-- Note: You are editing a temporary file. Whenever you save this file the
-- changes are applied to the profile and the script is restarted.
-- This event is raised after every profile update, before drawing.
function updateHandler(profile, eventArgs)
-- In this example we only want to update once per frame when the keyboard is
-- updated. If you don't do this the updateHandler will trigger on every
-- device's update.
if eventArgs.DeviceType != "keyboard" then
return
end
-- Custom update code here
end
local x = 40;
local iter = 0;
--local thisBrush = Brushes.GetRandomColor();
local thisBrush = Brushes.GetSolidColorBrush(Brushes.GetColor(255, 255, 0, 0));
local colors = {};
colors[Brushes.GetColor(255, 255, 0, 0)] = 0; -- red
colors[Brushes.GetColor(255, 255, 0, 255)] = 0.16; -- purple
colors[Brushes.GetColor(255, 0, 0, 255)] = 0.33; -- blue
colors[Brushes.GetColor(255, 0, 255, 255)] = 0.5; -- cyan
colors[Brushes.GetColor(255, 0, 255, 0)] = 0.66; -- green
colors[Brushes.GetColor(255, 255, 255, 0)] = 0.83; -- yellow
colors[Brushes.GetColor(255, 255, 0, 0)] = 1; -- red
local rainbowBrush = Brushes.GetLinearGradientBrush(colors);
-- This event is raised after every profile draw, after updating.
function drawHandler(profile, eventArgs)
-- In this example we only want to draw to the keyboard. Each device has it's
-- own drawing event
if eventArgs.DeviceType != "keyboard" then
return
end
-- Custom draw code here
if not eventArgs.DataModel.Spotify.Playing then
if iter % 50 < 25 then
eventArgs.Drawing.DrawRectangle(thisBrush, 0, 0, 30, 30);
end
iter = iter + 1;
return
end
iter = iter + 1;
if iter % 50 ~= 0 and eventArgs.DataModel.Spotify.Playing then
eventArgs.Drawing.DrawText(rainbowBrush, x, -2.4, eventArgs.DataModel.Spotify.SongName, 12);
x = x - .6;
end
if x < -70 then
x = 40;
end
end
-- Register the default events, you can rename/remove these if you so desire.
-- These events are raised every 40 ms (25 times a second).
Events.DeviceUpdating.add(updateHandler);
Events.DeviceDrawing.add(drawHandler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment