static void Main() { var config = new NLog.Config.LoggingConfiguration(); // Targets where to log to: File and Console var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "debugtool.log" }; // Rules for mapping loggers to targets config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); // Apply config LogManager.Configuration = config; RGBSurface surface = RGBSurface.Instance; LoadDeviceProviders(); surface.AlignDevices(); foreach (IRGBDevice device in surface.Devices) { device.UpdateMode = DeviceUpdateMode.Sync | DeviceUpdateMode.SyncBack; } UpdateTrigger = new TimerUpdateTrigger { UpdateFrequency = 1.0 / 60 }; surface.RegisterUpdateTrigger(UpdateTrigger); ILedGroup group = new ListLedGroup(surface.Leds); // Create new gradient IGradient gradient = new RainbowGradient(); // Add a MoveGradientDecorator to the gradient gradient.AddDecorator(new RGB.NET.Decorators.Gradient.MoveGradientDecorator()); // Make new LinearGradientBrush from gradient LinearGradientBrush nBrush = new LinearGradientBrush(gradient); // Apply LinearGradientBrush to led group group.Brush = nBrush; // Start UpdateTrigger, without this, the gradient will be drawn, but will not move. UpdateTrigger.Start(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
/// <summary> /// Updates the effect. /// </summary> /// <param name="deltaTime">The elapsed time (in seconds) since the last update.</param> public override void Update(float deltaTime) { float movement = Speed * deltaTime; if (!Direction) { movement = -movement; } // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull if (Brush.Gradient is LinearGradient) { LinearGradient linearGradient = (LinearGradient)Brush.Gradient; movement /= 360f; foreach (GradientStop gradientStop in linearGradient.GradientStops) { gradientStop.Offset = gradientStop.Offset + movement; if (gradientStop.Offset > 1f) { gradientStop.Offset -= 1f; } else if (gradientStop.Offset < 0) { gradientStop.Offset += 1f; } } } else if (Brush.Gradient is RainbowGradient) { RainbowGradient rainbowGradient = (RainbowGradient)Brush.Gradient; // RainbowGradient is calculated inverse but the movement should be the same for all. movement *= -1; rainbowGradient.StartHue += movement; rainbowGradient.EndHue += movement; if (rainbowGradient.StartHue > 360f && rainbowGradient.EndHue > 360f) { rainbowGradient.StartHue -= 360f; rainbowGradient.EndHue -= 360f; } else if (rainbowGradient.StartHue < -360f && rainbowGradient.EndHue < -360f) { rainbowGradient.StartHue += 360f; rainbowGradient.EndHue += 360f; } } }
/// <summary> /// Paints a moving gradient effect on a given ILedGroup /// </summary> /// <param name="group">The ILedGroup to apply the brush to</param> /// <param name="trigger">The UpdateTrigger registered to the RGBSurface used</param> public static void PaintGradient(ILedGroup group, TimerUpdateTrigger trigger) { // Create new gradient IGradient gradient = new RainbowGradient(); // Add a MoveGradientDecorator to the gradient gradient.AddDecorator(new RGB.NET.Decorators.Gradient.MoveGradientDecorator()); // Make new LinearGradientBrush from gradient LinearGradientBrush nBrush = new LinearGradientBrush(gradient); // Apply LinearGradientBrush to led group group.Brush = nBrush; // Start UpdateTrigger, without this, the gradient will be drawn, but will not move. trigger.Start(); }
public static void Main() { try { if (!CueSDK.IsSDKAvailable()) { Console.WriteLine("Ded"); Console.ReadKey(true); Environment.Exit(0); } CueSDK.Initialize(); Console.WriteLine("Initialized with x64-SDK"); CueSDK.UpdateMode = UpdateMode.Continuous; var keyboard = CueSDK.KeyboardSDK; keyboard.Brush = (SolidColorBrush)Color.Black; var rainbowGradient = new RainbowGradient(0, 720); new RectangleLedGroup(keyboard, CorsairLedId.Q, CorsairLedId.D) { Brush = new LinearGradientBrush(rainbowGradient) }.Exclude(CorsairLedId.Q, CorsairLedId.E); for (var i = 0; i < 100; i++) { rainbowGradient.StartHue += 10f; rainbowGradient.EndHue += 10f; Thread.Sleep(100); } } catch (CUEException ex) { Console.WriteLine("CUE Exception! ErrorCode: " + Enum.GetName(typeof(CorsairError), ex.Error)); } catch (WrapperException ex) { Console.WriteLine("Wrapper Exception! Message:" + ex.Message); } catch (Exception ex) { Console.WriteLine("Exception! Message:" + ex.Message); } while (true) { Thread.Sleep(1000); } }
static void Main(string[] args) { try { OpenRGBDeviceProvider.Instance.DeviceDefinitions.Add(new OpenRGBServerDefinition { ClientName = "TestProgram", Ip = "127.0.0.1", Port = 6742 }); List <IRGBDeviceProvider> deviceProviders = new List <IRGBDeviceProvider> { OpenRGBDeviceProvider.Instance, WootingDeviceProvider.Instance }; using RGBSurface surface = new RGBSurface(); surface.RegisterUpdateTrigger(new TimerUpdateTrigger()); foreach (IRGBDeviceProvider dp in deviceProviders) { surface.Load(dp); } ListLedGroup ledgroup = new ListLedGroup(surface, surface.Leds); RainbowGradient gradient = new RainbowGradient(); gradient.AddDecorator(new MoveGradientDecorator(surface)); ledgroup.Brush = new TextureBrush(new LinearGradientTexture(new Size(1, 1), gradient)); foreach (IRGBDevice d in surface.Devices) { Console.WriteLine($"Found {d.DeviceInfo.DeviceName}"); } Console.ReadLine(); surface?.Dispose(); foreach (IRGBDeviceProvider dp in deviceProviders) { dp.Dispose(); } } catch (Exception e) { Console.WriteLine($"Exception: {e}"); } }
static void Main(string[] args) { Console.WriteLine("Currently modes are supported: rainbow and sync"); Console.WriteLine("For rainbow, just run the exe"); Console.WriteLine("For sync, add the argument sync -> eg. 'RGB.exe sync'"); RGBSurface surface = RGBSurface.Instance; bool sync = false; if (args != null && args.Length > 0 && args[0] == "sync") { sync = true; Console.WriteLine("Starting sync mode..."); } else { Console.WriteLine("Starting rainbow mode..."); } if (sync) { surface.LoadDevices(AsusDeviceProvider.Instance, exclusiveAccessIfPossible: false, throwExceptions: true); surface.LoadDevices(CorsairDeviceProvider.Instance, exclusiveAccessIfPossible: true, throwExceptions: true); surface.LoadDevices(LogitechDeviceProvider.Instance, exclusiveAccessIfPossible: true, throwExceptions: true); } else { surface.LoadDevices(AsusDeviceProvider.Instance, exclusiveAccessIfPossible: true, throwExceptions: true); surface.LoadDevices(CorsairDeviceProvider.Instance, exclusiveAccessIfPossible: true, throwExceptions: true); surface.LoadDevices(LogitechDeviceProvider.Instance, exclusiveAccessIfPossible: true, throwExceptions: true); } surface.AlignDevices(); Console.WriteLine($"Found {surface.Devices.Count()} devices!"); foreach (var dev in surface.Devices) { Console.WriteLine($"dev: {dev.DeviceInfo.DeviceName}"); } if (sync) { AsusMainboardRGBDevice mainboard = RGBSurface.Instance.GetDevices <AsusMainboardRGBDevice>().FirstOrDefault(); if (mainboard == null) { throw new ApplicationException("No mainboard to sync with is loaded."); } mainboard.UpdateMode = DeviceUpdateMode.SyncBack; var group = new ListLedGroup(surface.Leds).Exclude(mainboard.ToArray()); group.Brush = new SyncBrush(((IRGBDevice)mainboard)[LedId.Mainboard1]); } else { foreach (var dev in surface.Devices) { dev.UpdateMode = DeviceUpdateMode.Sync; } var group = new ListLedGroup(surface.Leds); var gradient = new RainbowGradient(); var brush = new LinearGradientBrush(gradient); group.Brush = brush; System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Elapsed += (s, e) => { gradient.Move(7); }; aTimer.Interval = 100; aTimer.Start(); } TimerUpdateTrigger timerTrigger = new TimerUpdateTrigger(); timerTrigger.UpdateFrequency = 0.05; surface.RegisterUpdateTrigger(timerTrigger); timerTrigger.Start(); Console.Read(); }