-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52bf59f
commit ca1dbdd
Showing
14 changed files
with
851 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
CSharpMath.Uno.Example/CSharpMath.Uno.Example.Shared/ClockPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Page | ||
x:Class="CSharpMath.Uno.Example.Shared.ClockPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="using:CSharpMath.Uno.Example.Shared" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:skia="using:SkiaSharp.Views.UWP" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" | ||
mc:Ignorable="d"> | ||
|
||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
<skia:SKXamlCanvas | ||
x:Name="canvasView" | ||
VerticalAlignment="Stretch" | ||
PaintSurface="CanvasView_PaintSurface" /> | ||
</Grid> | ||
</Page> |
126 changes: 126 additions & 0 deletions
126
CSharpMath.Uno.Example/CSharpMath.Uno.Example.Shared/ClockPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using CSharpMath.SkiaSharp; | ||
using SkiaSharp; | ||
using SkiaSharp.Views.UWP; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
using static System.Math; | ||
|
||
namespace CSharpMath.Uno.Example.Shared { | ||
public sealed partial class ClockPage : Page { | ||
private readonly DispatcherTimer _timer; | ||
|
||
public ClockPage() { | ||
this.InitializeComponent(); | ||
_timer = new DispatcherTimer(); | ||
_timer.Interval = TimeSpan.FromMilliseconds(200); | ||
_timer.Tick += (s, e) => { | ||
canvasView.Invalidate(); | ||
}; | ||
this.Loaded += ClockPage_Loaded; | ||
this.Unloaded += ClockPage_Unloaded; | ||
} | ||
|
||
private void ClockPage_Loaded(object sender, RoutedEventArgs e) { | ||
_timer.Start(); | ||
} | ||
|
||
private void ClockPage_Unloaded(object sender, RoutedEventArgs e) { | ||
_timer.Stop(); | ||
} | ||
|
||
readonly SKPaint blackFillPaint = new SKPaint { | ||
Style = SKPaintStyle.Fill, | ||
Color = SKColors.Black | ||
}; | ||
readonly SKPaint whiteFillPaint = new SKPaint { | ||
Style = SKPaintStyle.Fill, | ||
Color = SKColors.White | ||
}; | ||
readonly SKPaint whiteStrokePaint = new SKPaint { | ||
Style = SKPaintStyle.Stroke, | ||
Color = SKColors.White, | ||
StrokeCap = SKStrokeCap.Round, | ||
IsAntialias = true | ||
}; | ||
readonly SKPaint redStrokePaint = new SKPaint { | ||
Style = SKPaintStyle.Stroke, | ||
Color = SKColors.Red, | ||
StrokeCap = SKStrokeCap.Round, | ||
IsAntialias = true | ||
}; | ||
readonly string[] labels = { | ||
// Four 4s make 1 to 12 using different operations | ||
@"$\frac{44+4}{4}$", | ||
@"$\frac{44}{44}$", | ||
@"$\frac{4}{4}+\frac{4}{4}$", | ||
@"$\frac{4+4+4}{4}$", | ||
@"$4+\frac{4-4}{4}$", | ||
@"$4+4^{4-4}$", | ||
@"$4+\frac{4+4}{4}$", | ||
@"$\frac{44}{4}-4$", | ||
@"$\sqrt{4}^{4-\frac{4}{4}}$", | ||
@"$\:\:(4-\frac{4}{4})^{\sqrt{4}}$", | ||
@"$\frac{44-4}{4}$", | ||
@"$\frac{4!}{\sqrt{4}}-\frac{4}{4}$" | ||
}; | ||
private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e) { | ||
var canvas = e.Surface.Canvas; | ||
canvas.Clear(SKColors.CornflowerBlue); | ||
canvas.Translate(e.Info.Width / 2, e.Info.Height / 2); | ||
canvas.Scale(e.Info.Width / 210f); | ||
canvas.DrawCircle(0, 0, 100, blackFillPaint); | ||
var painter = new TextPainter { FontSize = 8, TextColor = SKColors.White }; | ||
for (int i = 0; i < 60; i++) { | ||
// Dots | ||
canvas.Save(); | ||
canvas.RotateDegrees(6 * i); | ||
canvas.DrawCircle(0, -90, i % 5 == 0 ? 4 : 2, whiteFillPaint); | ||
canvas.Restore(); | ||
// Maths | ||
if (i % 5 == 0) { | ||
painter.LaTeX = labels[i / 5]; | ||
if (!(painter.Measure(e.Info.Width) is { } measure)) | ||
throw new Structures.InvalidCodePathException("Invalid LaTeX"); | ||
var θ = (90 - 6 * i) / 180f * PI; | ||
var sinθ = (float)Sin(θ); | ||
var cosθ = (float)Cos(θ); | ||
painter.Draw(canvas, | ||
new System.Drawing.PointF(75 * cosθ - (float)measure.Width / 2, | ||
-75 * sinθ - (float)measure.Height / 2), | ||
float.PositiveInfinity); | ||
} | ||
} | ||
var dateTime = DateTime.Now; | ||
// H | ||
canvas.Save(); | ||
canvas.RotateDegrees(30 * dateTime.Hour + dateTime.Minute / 2f); | ||
whiteStrokePaint.StrokeWidth = 12; | ||
canvas.DrawLine(0, 0, 0, -50, whiteStrokePaint); | ||
canvas.Restore(); | ||
// M | ||
canvas.Save(); | ||
canvas.RotateDegrees(6 * dateTime.Minute + dateTime.Second / 10f); | ||
whiteStrokePaint.StrokeWidth = 6; | ||
canvas.DrawLine(0, 0, 0, -65, whiteStrokePaint); | ||
canvas.Restore(); | ||
// S | ||
canvas.Save(); | ||
canvas.RotateDegrees(6f * (dateTime.Second + dateTime.Millisecond / 1000f)); | ||
redStrokePaint.StrokeWidth = 2; | ||
canvas.DrawLine(0, 0, 0, -75, redStrokePaint); | ||
canvas.Restore(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.