samples: add Hello/Demo samples for most BRUTAL packages (#19)

Add samples/, a collection of single-file .NET 10 apps run with
`dotnet run <file>.cs`. Hello/ has one minimal sample per package
that has a public API, many of them headless; Demo/ has fuller
programs that combine packages into a more interesting application.

samples/README.md indexes every sample and covers the layout, error
handling and per-OS requirements.
This commit is contained in:
Rian Drake 2026-10-27 09:10:25 +13:00 • committed by GitHub
commit 7a3b72d843
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

40
samples/Hello/HelloStb.cs Normal file
View file

@ -0,0 +1,40 @@
/*
* HelloStb
*
* Writes a generated gradient to a PNG with stb_image_write, reads it back with stb_image and
* prints a pixel.
*/
#:package Ahwoo.Brutal.Stb@2026.10.2
#:package Ahwoo.Brutal.Numerics@2026.10.1
// RIAN: Warning this library is handy for PNG, but it's pretty slow at runtime.
using System.Runtime.InteropServices;
using Brutal.Numerics;
using Brutal.StbApi;
const int WIDTH = 64;
const int HEIGHT = 64;
Run();
static void Run()
{
// Generate an RGB gradient.
var pixels = new byte3[WIDTH * HEIGHT];
for (var y = 0; y < HEIGHT; y++)
{
for (var x = 0; x < WIDTH; x++)
pixels[y * WIDTH + x] = new byte3((byte)(x * 4), (byte)(y * 4), 128);
}
var path = Path.Combine(Path.GetTempPath(), "HelloStb.png");
Stb.WritePng(path, WIDTH, HEIGHT, 3, MemoryMarshal.AsBytes(pixels.AsSpan()));
Console.WriteLine($"Wrote {path}");
// Freed when Run returns.
using var image = Stb.Load(path);
Console.WriteLine($"Loaded {image.Width}x{image.Height}, {image.Channels} channels");
Console.WriteLine($"Pixel (63, 0) = {image.AsSpan<byte3>()[63]}");
}