Skip to content

Instantly share code, notes, and snippets.

@juanpaexpedite
Created May 19, 2020 10:28
Show Gist options
  • Save juanpaexpedite/86fe7cd8fc16ad24c912569defe64d75 to your computer and use it in GitHub Desktop.
Save juanpaexpedite/86fe7cd8fc16ad24c912569defe64d75 to your computer and use it in GitHub Desktop.
(byte Min, byte Value, byte Max,byte speed, bool Increasing) TextSize;
(byte Min, byte Value , byte Max, byte speed, bool Increasing) Red;
(byte Min, byte Value, byte Max, byte speed, bool Increasing) Green;
(byte Min, byte Value, byte Max, byte speed, bool Increasing) Blue;
Random dice = new Random();
SKPaint textpaint;
private void Init()
{
TextSize = (10, 128, 200,1, true);
Red = (0, (byte)dice.Next(0, 128), 200, (byte)dice.Next(0, 5), true);
Green = (0, (byte)dice.Next(0, 128), 200, (byte)dice.Next(0, 5), true);
Blue = (0, (byte)dice.Next(0, 128), 200, (byte)dice.Next(0, 5), true);
textpaint = new SKPaint()
{
IsAntialias = true,
TextAlign = SKTextAlign.Center,
TextSize = TextSize.Value,
SubpixelText = true,
Color = new SKColor(Red.Value, Green.Value, Blue.Value)
};
}
private void Update()
{
Update(ref TextSize);
Update(ref Red);
Update(ref Green);
Update(ref Blue);
textpaint.TextSize = TextSize.Value;
textpaint.Color = new SKColor(Red.Value, Green.Value, Blue.Value);
}
private void Update(ref (byte Min, byte Value, byte Max, byte speed, bool Increasing) range)
{
if (range.Increasing)
{
range.Value+=range.speed;
if (range.Value > range.Max)
range.Increasing = false;
}
else
{
range.Value-= range.speed;
if (range.Value < range.Min)
range.Increasing = true;
}
}
private void Draw(SKCanvas canvas, int width, int height)
{
canvas.DrawText("SkiaSharp", width / 2f , (height + TextSize.Value) / 2f, textpaint);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment