-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientDrawing.cs
62 lines (47 loc) · 1.49 KB
/
ClientDrawing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Silk.NET.Input;
using SkiaSharp;
namespace drawing;
public unsafe partial class Client
{
SKRect rectangle = new(100, 100, 400, 400);
void OnKeyEvent(KeyEvent key)
{
// Move the rectangle 10px to the right when pressing the right key
if (key.IsPress && key.KeyCode == Key.Right)
{
var offset = 10;
// Move faster if shift is held
if (keyboard.IsKeyPressed(Key.ShiftLeft))
offset *= 5;
rectangle.Offset(offset, 0);
}
}
void Draw()
{
// Colours
var red = new SKColor(255, 0, 0);
var green = new SKColor(0, 255, 0);
var blue = new SKColor(0, 0, 255);
// Dark blue background
bitmap.FillRectangle(new SKRect(0, 0, WindowWidth, WindowHeight), new SKColor(5, 10, 35));
// Blue rectangle
bitmap.FillRectangle(rectangle, blue);
// Red sin wave
for (int x = 0; x < WindowWidth; x++)
{
var sin = MathF.Sin(x / (float)WindowWidth * MathF.PI * 2);
var y = (sin + 1) / 2 * WindowHeight;
bitmap.DrawPixel(x, (int)y, red);
}
// Raw canvas drawing
bitmap.canvas.DrawCircle(new SKPoint(400, 400), 80, new SKPaint()
{
Color = green,
IsStroke = true,
IsAntialias = true,
StrokeWidth = 8
});
}
public int WindowWidth => window.Size.X;
public int WindowHeight => window.Size.Y;
}