mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-10 20:46:24 +00:00
Added color-blending
This commit is contained in:
1 parent
0a47642c38
commit
22c23af4fd
4 files changed
+99
-25
No files matched your search
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -48,10 +47,10 @@ namespace SimpleDevTest
|
||||
keyboard[CorsairKeyboardKeyId.G].Led.Color = Color.Green;
|
||||
keyboard['B'].Led.Color = Color.Blue;
|
||||
|
||||
// Lock the 'r', 'g', 'b' keys. We want them to stay like this forever
|
||||
keyboard['R'].Led.IsLocked = true;
|
||||
keyboard['G'].Led.IsLocked = true;
|
||||
keyboard['B'].Led.IsLocked = true;
|
||||
// Lock the 'r', 'g', 'b' keys. We want them to stay like this forever (commented since it looks quite stupid later, but feel free tu uncomment this)
|
||||
//keyboard['R'].Led.IsLocked = true;
|
||||
//keyboard['G'].Led.IsLocked = true;
|
||||
//keyboard['B'].Led.IsLocked = true;
|
||||
|
||||
// Ink the letters of 'white' white
|
||||
ListKeyGroup whiteGroup = new ListKeyGroup(keyboard, CorsairKeyboardKeyId.W, CorsairKeyboardKeyId.H, CorsairKeyboardKeyId.I, CorsairKeyboardKeyId.T, CorsairKeyboardKeyId.E)
|
||||
@@ -73,11 +72,11 @@ namespace SimpleDevTest
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Now let us move a orange point random over the keyboard
|
||||
// Now let us move some points random over the keyboard
|
||||
// Something like this could become some sort of effect
|
||||
|
||||
// Initialize needed stuff
|
||||
const float SPEED = 8f; // mm/tick
|
||||
const float SPEED = 4f; // mm/tick
|
||||
Random random = new Random();
|
||||
|
||||
// Remove all the groups we created above to clear the keyboard
|
||||
@@ -96,30 +95,54 @@ namespace SimpleDevTest
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
|
||||
// Set keyboard 'background' to something fancy
|
||||
keyboard.Brush = new SolidColorBrush(Color.DarkSlateBlue);
|
||||
// Set keyboard 'background' to something neutral
|
||||
keyboard.Brush = new SolidColorBrush(Color.Black);
|
||||
|
||||
// Spawn our point (rectangle since circles are too hard to calculate :p) in the top-left corner (right over G1 or on ESC depending on your keyboard)
|
||||
RectangleF point = new RectangleF(keyboard.KeyboardRectangle.X, keyboard.KeyboardRectangle.Y, 40, 40);
|
||||
// Define how many points we have
|
||||
const int NUM_POINTS = 6;
|
||||
|
||||
// Create a new KeyGroup to represent our point on the keyboard
|
||||
RectangleKeyGroup pointGroup = new RectangleKeyGroup(keyboard, point, 0.1f)
|
||||
{ Brush = new SolidColorBrush(Color.Orange) };
|
||||
// The points we want to draw (rectangle since circles are too hard to calculate :p)
|
||||
RectangleF[] points = new RectangleF[NUM_POINTS];
|
||||
|
||||
// KeyGroups which represents our point on the keyboard
|
||||
RectangleKeyGroup[] pointGroups = new RectangleKeyGroup[NUM_POINTS];
|
||||
|
||||
// Target of our movement
|
||||
PointF target = new PointF(point.X, point.Y);
|
||||
PointF[] targets = new PointF[NUM_POINTS];
|
||||
|
||||
// Initialize all the stuff
|
||||
for (int i = 0; i < NUM_POINTS; i++)
|
||||
{
|
||||
// Spawn our point in the top-left corner (right over G1 or on ESC depending on your keyboard)
|
||||
points[i] = new RectangleF(keyboard.KeyboardRectangle.X, keyboard.KeyboardRectangle.Y, 60, 60);
|
||||
pointGroups[i] = new RectangleKeyGroup(keyboard, points[i], 0.1f) { Brush = new SolidColorBrush(Color.White) };
|
||||
targets[i] = new PointF(points[i].X, points[i].Y);
|
||||
}
|
||||
|
||||
// We set colors manually since white points are kinda boring (notice, that we use alpha values)
|
||||
pointGroups[0].Brush = new SolidColorBrush(Color.FromArgb(127, 255, 0, 0));
|
||||
pointGroups[1].Brush = new SolidColorBrush(Color.FromArgb(127, 0, 255, 0));
|
||||
pointGroups[2].Brush = new SolidColorBrush(Color.FromArgb(127, 0, 0, 255));
|
||||
pointGroups[3].Brush = new SolidColorBrush(Color.FromArgb(127, 255, 0, 255));
|
||||
pointGroups[4].Brush = new SolidColorBrush(Color.FromArgb(127, 255, 255, 0));
|
||||
pointGroups[5].Brush = new SolidColorBrush(Color.FromArgb(127, 0, 255, 255));
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Choose new target if we arrived
|
||||
if (point.Contains(target))
|
||||
target = new PointF((float)(keyboard.KeyboardRectangle.X + (random.NextDouble() * keyboard.KeyboardRectangle.Width)),
|
||||
(float)(keyboard.KeyboardRectangle.Y + (random.NextDouble() * keyboard.KeyboardRectangle.Height)));
|
||||
else
|
||||
// Calculate movement
|
||||
point.Location = Interpolate(point.Location, target, SPEED); // It would be better to calculate from the center of our rectangle but the easy way is enough here
|
||||
// Calculate all the points
|
||||
for (int i = 0; i < NUM_POINTS; i++)
|
||||
{
|
||||
// Choose new target if we arrived
|
||||
if (points[i].Contains(targets[i]))
|
||||
targets[i] = new PointF((float)(keyboard.KeyboardRectangle.X + (random.NextDouble() * keyboard.KeyboardRectangle.Width)),
|
||||
(float)(keyboard.KeyboardRectangle.Y + (random.NextDouble() * keyboard.KeyboardRectangle.Height)));
|
||||
else
|
||||
// Calculate movement
|
||||
points[i].Location = Interpolate(points[i].Location, targets[i], SPEED); // It would be better to calculate from the center of our rectangle but the easy way is enough here
|
||||
|
||||
// Move our rectangle to the new position
|
||||
pointGroup.Rectangle = point;
|
||||
// Move our rectangle to the new position
|
||||
pointGroups[i].Rectangle = points[i];
|
||||
}
|
||||
|
||||
// Update changed leds
|
||||
keyboard.UpdateLeds();
|
||||
|
||||
Reference in new issue
Block a user