From cd8d3f6765b00fc9eeab8a14c622757c735c81a0 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 12 Jun 2016 04:17:46 +0200 Subject: [PATCH 1/2] Fixed lack of randomness in rapid calls of GetRandomRainbowColor --- Artemis/Artemis/Utilities/ColorHelpers.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Artemis/Artemis/Utilities/ColorHelpers.cs b/Artemis/Artemis/Utilities/ColorHelpers.cs index bdefa0ec5..fb96440e3 100644 --- a/Artemis/Artemis/Utilities/ColorHelpers.cs +++ b/Artemis/Artemis/Utilities/ColorHelpers.cs @@ -7,6 +7,8 @@ namespace Artemis.Utilities { public static class ColorHelpers { + private static readonly Random _rand = new Random(); + /// /// Comes up with a 'pure' psuedo-random color /// @@ -14,9 +16,8 @@ namespace Artemis.Utilities public static Color GetRandomRainbowColor() { var colors = new List(); - var rand = new Random(); for (var i = 0; i < 3; i++) - colors.Add(rand.Next(0, 256)); + colors.Add(_rand.Next(0, 256)); var highest = colors.Max(); var lowest = colors.Min(); @@ -31,9 +32,8 @@ namespace Artemis.Utilities public static System.Windows.Media.Color GetRandomRainbowMediaColor() { var colors = new List(); - var rand = new Random(); for (var i = 0; i < 3; i++) - colors.Add((byte) rand.Next(0, 256)); + colors.Add((byte)_rand.Next(0, 256)); var highest = colors.Max(); var lowest = colors.Min(); From eba34be67bc086e545e3f52a5f67da7c36c93f42 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 12 Jun 2016 04:19:39 +0200 Subject: [PATCH 2/2] Added Bouncing-Bubbles-Effect --- Artemis/Artemis/App.config | 24 ++++ Artemis/Artemis/Artemis.csproj | 20 +++ .../InjectionModules/ArtemisModules.cs | 2 + .../Artemis/Modules/Effects/Bubbles/Bubble.cs | 65 +++++++++ .../Effects/Bubbles/Bubbles.Designer.cs | 110 +++++++++++++++ .../Modules/Effects/Bubbles/Bubbles.settings | 27 ++++ .../Modules/Effects/Bubbles/BubblesModel.cs | 107 ++++++++++++++ .../Effects/Bubbles/BubblesSettings.cs | 56 ++++++++ .../Modules/Effects/Bubbles/BubblesView.xaml | 133 ++++++++++++++++++ .../Effects/Bubbles/BubblesView.xaml.cs | 12 ++ .../Effects/Bubbles/BubblesViewModel.cs | 25 ++++ 11 files changed, 581 insertions(+) create mode 100644 Artemis/Artemis/Modules/Effects/Bubbles/Bubble.cs create mode 100644 Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.Designer.cs create mode 100644 Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.settings create mode 100644 Artemis/Artemis/Modules/Effects/Bubbles/BubblesModel.cs create mode 100644 Artemis/Artemis/Modules/Effects/Bubbles/BubblesSettings.cs create mode 100644 Artemis/Artemis/Modules/Effects/Bubbles/BubblesView.xaml create mode 100644 Artemis/Artemis/Modules/Effects/Bubbles/BubblesView.xaml.cs create mode 100644 Artemis/Artemis/Modules/Effects/Bubbles/BubblesViewModel.cs diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index 1e8822674..d3ab7c400 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -3,6 +3,7 @@ +
@@ -254,6 +255,29 @@ 4 + + + True + + + #FFFF0000 + + + True + + + 100 + + + 16 + + + 12 + + + 14 + + TypeWave diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 45ae2cfd6..a97a823b3 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -318,6 +318,18 @@ + + + True + True + Bubbles.settings + + + + + BubblesView.xaml + + True True @@ -564,6 +576,10 @@ SettingsSingleFileGenerator AudioVisualization.Designer.cs + + SettingsSingleFileGenerator + Bubbles.Designer.cs + SettingsSingleFileGenerator TypeWave.Designer.cs @@ -650,6 +666,10 @@ + + Designer + MSBuild:Compile + MSBuild:Compile Designer diff --git a/Artemis/Artemis/InjectionModules/ArtemisModules.cs b/Artemis/Artemis/InjectionModules/ArtemisModules.cs index bc882aa9f..2ec4602f1 100644 --- a/Artemis/Artemis/InjectionModules/ArtemisModules.cs +++ b/Artemis/Artemis/InjectionModules/ArtemisModules.cs @@ -3,6 +3,7 @@ using Artemis.DeviceProviders.Corsair; using Artemis.DeviceProviders.Logitech; using Artemis.DeviceProviders.Razer; using Artemis.Modules.Effects.AudioVisualizer; +using Artemis.Modules.Effects.Bubbles; using Artemis.Modules.Effects.TypeWave; using Artemis.Modules.Effects.WindowsProfile; using Artemis.Modules.Games.CounterStrike; @@ -26,6 +27,7 @@ namespace Artemis.InjectionModules // Effects Bind().To().InSingletonScope(); Bind().To().InSingletonScope(); + Bind().To().InSingletonScope(); Bind().To().InSingletonScope(); // Games diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/Bubble.cs b/Artemis/Artemis/Modules/Effects/Bubbles/Bubble.cs new file mode 100644 index 000000000..535e03428 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Bubbles/Bubble.cs @@ -0,0 +1,65 @@ +using System.Drawing; +using System.Windows; +using Point = System.Windows.Point; + +namespace Artemis.Modules.Effects.Bubbles +{ + public class Bubble + { + #region Properties & Fields + + private Brush _brush; + + private Color _color; + public Color Color + { + get { return _color; } + set + { + _color = value; + _brush = new SolidBrush(_color); + } + } + + public int Radius { get; set; } + public Point Position { get; private set; } + public Vector Direction { get; private set; } + + #endregion + + #region Constructors + + public Bubble(Color color, int radius, Point position, Vector direction) + { + this.Color = color; + this.Radius = radius; + this.Position = position; + this.Direction = direction; + } + + #endregion + + #region Methods + + public void CheckCollision(Rect border) + { + if (Position.X - Radius < border.X || Position.X + Radius > border.X + border.Width) + Direction = new Vector(Direction.X * -1, Direction.Y); + + if (Position.Y - Radius < border.Y || Position.Y + Radius > border.Y + border.Height) + Direction = new Vector(Direction.X, Direction.Y * -1); + } + + public void Move() + { + Position += Direction; + } + + public void Draw(Graphics g) + { + g.FillEllipse(_brush, (float)Position.X - Radius, (float)Position.Y - Radius, Radius * 2, Radius * 2); + } + + #endregion + } +} diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.Designer.cs b/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.Designer.cs new file mode 100644 index 000000000..d5fd2c24e --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.Designer.cs @@ -0,0 +1,110 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Artemis.Modules.Effects.Bubbles { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class Bubbles : global::System.Configuration.ApplicationSettingsBase { + + private static Bubbles defaultInstance = ((Bubbles)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Bubbles()))); + + public static Bubbles Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool IsRandomColors { + get { + return ((bool)(this["IsRandomColors"])); + } + set { + this["IsRandomColors"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("#FFFF0000")] + public global::System.Windows.Media.Color BubbleColor { + get { + return ((global::System.Windows.Media.Color)(this["BubbleColor"])); + } + set { + this["BubbleColor"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool IsShiftColors { + get { + return ((bool)(this["IsShiftColors"])); + } + set { + this["IsShiftColors"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("100")] + public int BubbleSize { + get { + return ((int)(this["BubbleSize"])); + } + set { + this["BubbleSize"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("16")] + public int MoveSpeed { + get { + return ((int)(this["MoveSpeed"])); + } + set { + this["MoveSpeed"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("12")] + public int ShiftColorSpeed { + get { + return ((int)(this["ShiftColorSpeed"])); + } + set { + this["ShiftColorSpeed"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("14")] + public int BubbleCount { + get { + return ((int)(this["BubbleCount"])); + } + set { + this["BubbleCount"] = value; + } + } + } +} diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.settings b/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.settings new file mode 100644 index 000000000..fc496b031 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.settings @@ -0,0 +1,27 @@ + + + + + + True + + + #FFFF0000 + + + True + + + 100 + + + 16 + + + 12 + + + 14 + + + \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesModel.cs b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesModel.cs new file mode 100644 index 000000000..415c2cdd8 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesModel.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq.Dynamic; +using System.Windows; +using Artemis.Managers; +using Artemis.Models; +using Artemis.Models.Profiles; +using Artemis.Utilities; +using Brush = System.Windows.Media.Brush; + +namespace Artemis.Modules.Effects.Bubbles +{ + public class BubblesModel : EffectModel + { + #region Properties & Fields + + private static readonly Random _random = new Random(); + + private const int SCALE = 100; + + private readonly List _bubbles = new List(); + + public BubblesSettings Settings { get; } + + #endregion + + #region Constructors + + public BubblesModel(MainManager mainManager, BubblesSettings settings) + : base(mainManager, null) + { + Name = "Bubbles"; + Settings = settings; + Initialized = false; + } + + #endregion + + #region Methods + + public override void Enable() + { + Rect rect = MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(SCALE); + + for (int i = 0; i < Settings.BubbleCount; i++) + { + Color color = Settings.IsRandomColors ? ColorHelpers.GetRandomRainbowColor() : ColorHelpers.ToDrawingColor(Settings.BubbleColor); + // -Settings.MoveSpeed because we want to spawn at least one move away from borders + double initialPositionX = ((rect.Width - (Settings.BubbleSize * 2) - Settings.MoveSpeed) * _random.NextDouble()) + Settings.BubbleSize; + double initialPositionY = ((rect.Height - (Settings.BubbleSize * 2) - Settings.MoveSpeed) * _random.NextDouble()) + Settings.BubbleSize; + double initialDirectionX = (Settings.MoveSpeed * _random.NextDouble()) * (_random.Next(1) == 0 ? -1 : 1); + double initialDirectionY = (Settings.MoveSpeed - Math.Abs(initialDirectionX)) * (_random.Next(1) == 0 ? -1 : 1); + + _bubbles.Add(new Bubble(color, Settings.BubbleSize, new System.Windows.Point(initialPositionX, initialPositionY), new Vector(initialDirectionX, initialDirectionY))); + } + + Initialized = true; + } + + public override void Dispose() + { + _bubbles.Clear(); + Initialized = false; + } + + public override void Update() + { + Rect keyboardRectangle = MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(SCALE); + foreach (Bubble bubble in _bubbles) + { + if (Settings.IsShiftColors) + bubble.Color = ColorHelpers.ShiftColor(bubble.Color, Settings.IsRandomColors ? (int)Math.Round(Settings.ShiftColorSpeed * _random.NextDouble()) : Settings.ShiftColorSpeed); + + bubble.CheckCollision(keyboardRectangle); + bubble.Move(); + } + } + + public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, bool renderHeadsets) + { + keyboard = null; + mouse = null; + headset = null; + + if (!_bubbles.Any()) return; + + keyboard = MainManager.DeviceManager.ActiveKeyboard.KeyboardBitmap(SCALE); + using (Graphics g = Graphics.FromImage(keyboard)) + { + g.Clear(Color.Transparent); + g.SmoothingMode = SmoothingMode.HighQuality; + + foreach (Bubble bubble in _bubbles) + bubble.Draw(g); + } + } + + public override List GetRenderLayers(bool renderMice, bool renderHeadsets) + { + return null; + } + + #endregion + } +} diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesSettings.cs b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesSettings.cs new file mode 100644 index 000000000..57aec84c2 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesSettings.cs @@ -0,0 +1,56 @@ +using System.Windows.Media; +using Artemis.Models; + +namespace Artemis.Modules.Effects.Bubbles +{ + public class BubblesSettings : EffectSettings + { + public BubblesSettings() + { + Load(); + } + + public bool IsRandomColors { get; set; } + public Color BubbleColor { get; set; } + public bool IsShiftColors { get; set; } + public int ShiftColorSpeed { get; set; } + public int BubbleSize { get; set; } + public int MoveSpeed { get; set; } + public int BubbleCount { get; set; } + + public sealed override void Load() + { + IsRandomColors = Bubbles.Default.IsRandomColors; + BubbleColor = Bubbles.Default.BubbleColor; + IsShiftColors = Bubbles.Default.IsShiftColors; + ShiftColorSpeed = Bubbles.Default.ShiftColorSpeed; + BubbleSize = Bubbles.Default.BubbleSize; + MoveSpeed = Bubbles.Default.MoveSpeed; + BubbleCount = Bubbles.Default.BubbleCount; + } + + public sealed override void Save() + { + Bubbles.Default.IsRandomColors = IsRandomColors; + Bubbles.Default.BubbleColor = BubbleColor; + Bubbles.Default.IsShiftColors = IsShiftColors; + Bubbles.Default.ShiftColorSpeed = ShiftColorSpeed; + Bubbles.Default.BubbleSize = BubbleSize; + Bubbles.Default.MoveSpeed = MoveSpeed; + Bubbles.Default.BubbleCount = BubbleCount; + + Bubbles.Default.Save(); + } + + public sealed override void ToDefault() + { + IsRandomColors = true; + BubbleColor = Color.FromArgb(255, 255, 0, 0); + IsShiftColors = true; + ShiftColorSpeed = 12; + BubbleSize = 100; + MoveSpeed = 16; + BubbleCount = 14; + } + } +} diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesView.xaml b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesView.xaml new file mode 100644 index 000000000..808e24da7 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesView.xaml @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bubble color + + + + + + Use random colors + + + + + + Shift through colors as the bubble moves + + + + + + Speed to shift colors at + + + + + + Bubble count + + + + + + Bubble size + + + + + + Bubble move speed + + + + + +