removing submodule
Some checks failed
build lightwatch / build (push) Failing after 5m6s

This commit is contained in:
2023-09-03 01:14:34 -04:00
parent d539dc9119
commit ed18dd911a
190 changed files with 1174526 additions and 4 deletions

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\RPiRgbLEDMatrix.csproj"/>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,29 @@
using RPiRgbLEDMatrix;
if (args.Length < 1)
{
Console.WriteLine("font-example.exe [font_path] <text>");
return -1;
}
string text = "Hello World!";
if (args.Length > 1)
text = args[1];
using var matrix = new RGBLedMatrix(32, 2, 1);
var canvas = matrix.CreateOffscreenCanvas();
using var font = new RGBLedFont(args[0]);
canvas.DrawText(font, 1, 6, new Color(0, 255, 0), text);
matrix.SwapOnVsync(canvas);
// run until user presses Ctrl+C
var running = true;
Console.CancelKeyPress += (_, e) =>
{
running = false;
e.Cancel = true; // do not terminate program with Ctrl+C, we need to dispose
};
while (running) Thread.Yield();
return 0;

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\RPiRgbLEDMatrix.csproj"/>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,74 @@
using RPiRgbLEDMatrix;
const int MaxHeight = 16;
const int ColorStep = 15;
const int FrameStep = 1;
using var matrix = new RGBLedMatrix(new RGBLedMatrixOptions { ChainLength = 2 });
var canvas = matrix.CreateOffscreenCanvas();
var rnd = new Random();
var points = new List<Point>();
var recycled = new Stack<Point>();
var frame = 0;
var running = true;
Console.CancelKeyPress += (s, e) =>
{
running = false;
e.Cancel = true; // don't terminate, we need to dispose
};
// run until user presses Ctrl+C
while (running)
{
var frameStart = Environment.TickCount64;
frame++;
if (frame % FrameStep == 0)
{
if (recycled.Count == 0)
points.Add(new Point(rnd.Next(0, canvas.Width - 1), 0));
else
{
var point = recycled.Pop();
point.X = rnd.Next(0, canvas.Width - 1);
point.Y = 0;
point.Recycled = false;
}
}
canvas.Clear();
foreach (var point in points)
{
if (point.Recycled) continue;
point.Y++;
if (point.Y - MaxHeight > canvas.Height)
{
point.Recycled = true;
recycled.Push(point);
}
for (var i = 0; i < MaxHeight; i++)
{
canvas.SetPixel(point.X, point.Y - i, new Color(0, 255 - i * ColorStep, 0));
}
}
matrix.SwapOnVsync(canvas);
// force 30 FPS
var elapsed = Environment.TickCount64 - frameStart;
if (elapsed < 33) Thread.Sleep(33 - (int)elapsed);
}
class Point
{
public int X;
public int Y;
public bool Recycled = false;
public Point(int x, int y) => (X, Y) = (x, y);
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\RPiRgbLEDMatrix.csproj"/>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,19 @@
using RPiRgbLEDMatrix;
using var matrix = new RGBLedMatrix(32, 2, 1);
var canvas = matrix.CreateOffscreenCanvas();
var centerX = canvas.Width / 2;
var centerY = canvas.Height / 2;
for (var i = 0; i < 1000; ++i)
{
for (var y = 0; y < canvas.Height; ++y)
for (var x = 0; x < canvas.Width; ++x)
canvas.SetPixel(x, y, new Color(i & 0xFF, x, y));
canvas.DrawCircle(centerX, centerY, 6, new Color(0, 0, 255));
canvas.DrawLine(centerX - 3, centerY - 3, centerX + 3, centerY + 3, new Color(0, 0, 255));
canvas.DrawLine(centerX - 3, centerY + 3, centerX + 3, centerY - 3, new Color(0, 0, 255));
matrix.SwapOnVsync(canvas);
}

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\RPiRgbLEDMatrix.csproj" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,40 @@
using RPiRgbLEDMatrix;
using System.Runtime.InteropServices;
using Color = RPiRgbLEDMatrix.Color;
Console.Write("GIF path: ");
var path = Console.ReadLine()!;
using var matrix = new RGBLedMatrix(32, 2, 1);
var canvas = matrix.CreateOffscreenCanvas();
Configuration.Default.PreferContiguousImageBuffers = true;
using var image = Image.Load<Rgb24>(path);
image.Mutate(o => o.Resize(canvas.Width, canvas.Height));
var running = true;
Console.CancelKeyPress += (s, e) =>
{
running = false;
e.Cancel = true; // don't terminate, we need to dispose
};
var frame = -1;
// preprocess frames to get delays and pixel buffers
var frames = image.Frames
.Select(f => (
Pixels: f.DangerousTryGetSinglePixelMemory(out var memory) ? memory : throw new("Could not get pixel buffer"),
Delay: f.Metadata.GetGifMetadata().FrameDelay * 10
)).ToArray();
// run until user presses Ctrl+C
while (running)
{
frame = (frame + 1) % frames.Length;
var data = MemoryMarshal.Cast<Rgb24, Color>(frames[frame].Pixels.Span);
canvas.SetPixels(0, 0, canvas.Width, canvas.Height, data);
matrix.SwapOnVsync(canvas);
Thread.Sleep(frames[frame].Delay);
}

View File

@@ -0,0 +1,33 @@
using RPiRgbLEDMatrix;
using var matrix = new RGBLedMatrix(new RGBLedMatrixOptions { Rows = 32, Cols = 64 });
var canvas = matrix.CreateOffscreenCanvas();
var maxBrightness = matrix.Brightness;
var rnd = new Random();
// run until user presses Ctrl+C
var running = true;
Console.CancelKeyPress += (_, e) =>
{
running = false;
e.Cancel = true; // do not terminate program with Ctrl+C, we need to dispose
};
var color = new Color(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
while (running)
{
if (matrix.Brightness < 1)
{
matrix.Brightness = maxBrightness;
color = new Color(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
}
else
{
matrix.Brightness--;
}
canvas.Fill(color);
matrix.SwapOnVsync(canvas);
Thread.Sleep(20);
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\RPiRgbLEDMatrix.csproj"/>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,90 @@
using RPiRgbLEDMatrix;
using System.Numerics;
const float MaxModuleSpeed = 0.1f;
const float FOV = 60f;
const float Scale = 1.1f;
const float LerpPow = 0.002f;
const int ChangePerFrames = 50;
using var leds = new RGBLedMatrix(32, 1, 1);
var canvas = leds.CreateOffscreenCanvas();
var (centerX, centerY) = (canvas.Width / 2, canvas.Height / 2);
var rnd = new Random();
var angleSpeed = new Vector3();
var nextAngleSpeed = new Vector3();
var frame = -1;
var rotateMatrix = Matrix4x4.Identity;
var scaleMatrix = Matrix4x4.CreateScale(Scale);
var projectMatrix = Matrix4x4.CreatePerspectiveFieldOfView(FOV / 180 * MathF.PI, 1, 0.1f, 100f);
var cameraMatrix = Matrix4x4.CreateLookAt(new(0, 0, 4), new(0, 0, 0), new(0, 1, 0));
// run until user presses Ctrl+C
var running = true;
Console.CancelKeyPress += (_, e) =>
{
running = false;
e.Cancel = true; // do not terminate program with Ctrl+C, we need to dispose
};
while (running)
{
var frameStart = Environment.TickCount64;
// update angle speed
frame = (frame + 1) % ChangePerFrames;
if(frame == 0)
nextAngleSpeed = new Vector3(
(rnd.NextSingle() * 2 - 1) * MaxModuleSpeed,
(rnd.NextSingle() * 2 - 1) * MaxModuleSpeed,
(rnd.NextSingle() * 2 - 1) * MaxModuleSpeed
);
angleSpeed = Vector3.Lerp(angleSpeed, nextAngleSpeed, LerpPow);
// update matrices
rotateMatrix *= Matrix4x4.CreateRotationX(angleSpeed.X);
rotateMatrix *= Matrix4x4.CreateRotationY(angleSpeed.Y);
rotateMatrix *= Matrix4x4.CreateRotationZ(angleSpeed.Z);
var matrix = scaleMatrix * rotateMatrix * cameraMatrix * projectMatrix;
// calculate points
var top1 = Vector4.Transform(new Vector3( 1, 1, 1), matrix);
var top2 = Vector4.Transform(new Vector3(-1, 1, 1), matrix);
var top3 = Vector4.Transform(new Vector3(-1, 1, -1), matrix);
var top4 = Vector4.Transform(new Vector3( 1, 1, -1), matrix);
var bot1 = Vector4.Transform(new Vector3( 1, -1, 1), matrix);
var bot2 = Vector4.Transform(new Vector3(-1, -1, 1), matrix);
var bot3 = Vector4.Transform(new Vector3(-1, -1, -1), matrix);
var bot4 = Vector4.Transform(new Vector3( 1, -1, -1), matrix);
// draw
canvas.Fill(new(0, 0, 0));
DrawLine(top1, top2);
DrawLine(top2, top3);
DrawLine(top3, top4);
DrawLine(top4, top1);
DrawLine(bot1, bot2);
DrawLine(bot2, bot3);
DrawLine(bot3, bot4);
DrawLine(bot4, bot1);
DrawLine(top1, bot1);
DrawLine(top2, bot2);
DrawLine(top3, bot3);
DrawLine(top4, bot4);
leds.SwapOnVsync(canvas);
// force 30 FPS
var elapsed = Environment.TickCount64 - frameStart;
if (elapsed < 33) Thread.Sleep(33 - (int)elapsed);
}
void DrawLine(Vector4 a, Vector4 b) => canvas.DrawLine(
(int)(a.X * a.W + centerX), (int)(a.Y * a.W + centerY),
(int)(b.X * b.W + centerX), (int)(b.Y * b.W + centerY),
new(255, 255, 255));

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\RPiRgbLEDMatrix.csproj"/>
</ItemGroup>
</Project>