mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-26 21:22:50 +08:00

* Adding social card infrastructure * Upgrades doc project to .NET 6 * Adds Playwright * Changes the console to a web project for Playwright * Adds social card template * Added blog content * Parallelized social image processing * Updating CI to use .NET 6 for docs build
37 lines
884 B
Markdown
37 lines
884 B
Markdown
Title: Canvas
|
|
Order: 60
|
|
Description: "**Canvas** is a widget that allows you to render arbitrary pixels to the console."
|
|
---
|
|
|
|
`Canvas` is a widget that allows you to render arbitrary "pixels"
|
|
(or _coxels_, as [Simon Cropp](https://twitter.com/SimonCropp/status/1331554791726534657?s=20)
|
|
suggested we should call them).
|
|
|
|
## Drawing primitives
|
|
|
|
```csharp
|
|
// Create a canvas
|
|
var canvas = new Canvas(16, 16);
|
|
|
|
// Draw some shapes
|
|
for(var i = 0; i < canvas.Width; i++)
|
|
{
|
|
// Cross
|
|
canvas.SetPixel(i, i, Color.White);
|
|
canvas.SetPixel(canvas.Width - i - 1, i, Color.White);
|
|
|
|
// Border
|
|
canvas.SetPixel(i, 0, Color.Red);
|
|
canvas.SetPixel(0, i, Color.Green);
|
|
canvas.SetPixel(i, canvas.Height - 1, Color.Blue);
|
|
canvas.SetPixel(canvas.Width - 1, i, Color.Yellow);
|
|
}
|
|
|
|
// Render the canvas
|
|
AnsiConsole.Render(canvas);
|
|
```
|
|
|
|
## Result
|
|
|
|
<?# AsciiCast cast="canvas" /?>
|