我有问题。我是SkiaSharp软件包的新手,所以我在以下问题中苦苦挣扎:我使用以下代码用SkiaSharp创建了TriangleGrid:
private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
// the the canvas and properties
var canvas = e.Surface.Canvas;
// get the screen density for scaling
var scale = Resources.DisplayMetrics.Density;
var scaledSize = new SKSize(e.Info.Width / scale, e.Info.Height / scale);
// handle the device screen density
canvas.Scale(scale);
SKPaint strokePaint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = SKColors.White,
StrokeWidth = 3,
IsAntialias = true,
};
int TrianglesVisiblePerRow = 4;
int TrianglesPerRow = 6;
int TriangleCountOnRow = 0;
int RowCountOnScreen = 0;
float TriangleWidth = scaledSize.Width / TrianglesVisiblePerRow;
float TriangleRowHeight = (float)Math.Sqrt(Math.Pow(TriangleWidth, 2) - (Math.Pow((scaledSize.Width / (TrianglesVisiblePerRow * 2)), 2)));
float X_Start_Cooridnate = -TriangleWidth;
float Y_Start_Cooridnate = 0;
while (Y_Start_Cooridnate < scaledSize.Height)
{
while (TriangleCountOnRow < TrianglesPerRow)
{
// Create the path
path = new SKPath();
path.MoveTo(X_Start_Cooridnate, Y_Start_Cooridnate);
path.LineTo(X_Start_Cooridnate + TriangleWidth, (TriangleRowHeight * RowCountOnScreen));
if (RowCountOnScreen % 2 != 0)
{
path.LineTo(-(TriangleWidth / 2) + (scaledSize.Width / (TrianglesVisiblePerRow * 2)) + (TriangleWidth * TriangleCountOnRow), (TriangleRowHeight * (RowCountOnScreen + 1)));
}
else
{
path.LineTo(-TriangleWidth + (scaledSize.Width / (TrianglesVisiblePerRow * 2)) + (TriangleWidth * TriangleCountOnRow), (TriangleRowHeight * (RowCountOnScreen + 1)));
}
path.LineTo(X_Start_Cooridnate, Y_Start_Cooridnate);
path.Close();
canvas.DrawPath(path, strokePaint);
TriangleCountOnRow += 1;
X_Start_Cooridnate += TriangleWidth;
}
// Create the path
path = new SKPath();
path.MoveTo(0, TriangleRowHeight);
path.LineTo(scaledSize.Width, TriangleRowHeight);
path.Close();
canvas.DrawPath(path, strokePaint);
RowCountOnScreen += 1;
if (RowCountOnScreen % 2 != 0)
{
X_Start_Cooridnate = -(TriangleWidth/2);
}
else
{
X_Start_Cooridnate = -TriangleWidth;
}
Y_Start_Cooridnate += TriangleRowHeight;
TriangleCountOnRow = 0;
}
}
现在,我想用一种颜色填充已经接触过的三角形,但是我不知道这是否有可能。因此,我需要代码,您可以在其中触摸一个三角形或多个三角形,并且该特定三角形获得不同的颜色。有人可以帮我这个忙吗??