public async void DrawCurveControlLines(Canvas2DContext ctx, BezierCurve curve) { await ctx.BeginPathAsync(); await ctx.MoveToAsync(curve.ControlPoint1.X, curve.ControlPoint1.Y); await ctx.LineToAsync(curve.StartPoint.X, curve.StartPoint.Y); //await ctx.SetStrokeStyleAsync("red"); await ctx.StrokeAsync(); await ctx.BeginPathAsync(); //await ctx.SetFillStyleAsync("yellow"); await ctx.ArcAsync(curve.ControlPoint1.X, curve.ControlPoint1.Y, 5, 0, Math.PI * 2); await ctx.FillAsync(); await ctx.BeginPathAsync(); await ctx.MoveToAsync(curve.ControlPoint2.X, curve.ControlPoint2.Y); await ctx.LineToAsync(curve.EndPoint.X, curve.EndPoint.Y); //await ctx.SetStrokeStyleAsync("red"); await ctx.StrokeAsync(); await ctx.BeginPathAsync(); // await ctx.SetFillStyleAsync("yellow"); await ctx.ArcAsync(curve.ControlPoint2.X, curve.ControlPoint2.Y, 5, 0, Math.PI * 2); await ctx.FillAsync(); }
internal async Task DrawPolygonAsync(Color fillColor, Color borderColor, float borderWidth, Point[] points) { if (points.Length == 0) { return; } await ctx.BeginPathAsync(); await ctx.MoveToAsync(points[0].X, points[0].Y); for (int i = 1; i < points.Length; i++) { await ctx.LineToAsync(points[i].X, points[i].Y); } await ctx.LineToAsync(points[0].X, points[0].Y); if (fillColor != null) { await this.SetFillColor(fillColor); await ctx.FillAsync(); } if (borderColor != null) { await this.SetStrokeColor(borderColor); await this.SetLineWidth(borderWidth); await ctx.StrokeAsync(); } }
private async Task TraceLineAsync(double x, double y) { if (_lastX is not null && _lastY is not null) { await _canvas2DContext.SetLineWidthAsync(LineWidth); await _canvas2DContext.BeginPathAsync(); await _canvas2DContext.MoveToAsync(_lastX.Value, _lastY.Value); await _canvas2DContext.LineToAsync(x, y); await _canvas2DContext.StrokeAsync(); } await _canvas2DContext.BeginPathAsync(); await _canvas2DContext.ArcAsync(x, y, PointSize, 0, Radius, anticlockwise : true); await _canvas2DContext.ClosePathAsync(); await _canvas2DContext.FillAsync(); _lastX = x; _lastY = y; }
/// <summary> /// 画表盘圆 ///</summary> ///<param name="strokeStyle"></param> ///<param name="radius">半径</param> ///<param name="fillStyle">填充色</param> /// <returns></returns> private async Task DrawCicleAsync(string strokeStyle, double radius, string fillStyle) { await _context.SaveAsync(); await _context.TranslateAsync(radius, radius); await _context.BeginPathAsync(); await _context.SetStrokeStyleAsync(strokeStyle); await _context.ArcAsync(0, 0, radius, 0, 2 *Math.PI, true); await _context.SetFillStyleAsync(fillStyle); await _context.FillAsync(); await _context.RestoreAsync(); }
public override async Task Draw(Canvas2DContext context) { await context.BeginPathAsync(); await context.ArcAsync(Position.X, Position.Y, Size / 2, 0, 2 *Math.PI); await context.SetFillStyleAsync("blue"); await context.FillAsync(); }
public static async Task DrawOn(this IDisplayable element, Canvas2DContext context) { await context.BeginPathAsync(); await context.ArcAsync(element.Position.X, element.Position.Y, element.Size / 2, 0, Math.PI * 2); await context.SetFillStyleAsync(element.Color); await context.FillAsync(); await context.ClosePathAsync(); }
public async void DrawPathPoints(Canvas2DContext ctx, List <PointF> pathpoints) { Utils.dOut("DrawPathPoints", pathpoints.Count); foreach (var point in pathpoints) { await ctx.BeginPathAsync(); await ctx.ArcAsync(point.X, point.Y, 2, 0, Math.PI * 2); await ctx.FillAsync(); } }
public async void DrawGrid(Canvas2DContext ctx) { var enemygrid = new EnemyGrid(); await ctx.BeginPathAsync(); enemygrid.GridPoints.Where(a => a.Row == 1).ToList().ForEach(async a => { await ctx.ArcAsync(a.Point.X, a.Point.Y, 5, 0, Math.PI * 2); }); await ctx.FillAsync(); await ctx.BeginPathAsync(); enemygrid.GridPoints.Where(a => a.Row == 2).ToList().ForEach(async a => { await ctx.ArcAsync(a.Point.X, a.Point.Y, 5, 0, Math.PI * 2); }); await ctx.FillAsync(); await ctx.BeginPathAsync(); enemygrid.GridPoints.Where(a => a.Row == 3).ToList().ForEach(async a => { await ctx.ArcAsync(a.Point.X, a.Point.Y, 5, 0, Math.PI * 2); }); await ctx.FillAsync(); await ctx.BeginPathAsync(); enemygrid.GridPoints.Where(a => a.Row == 4).ToList().ForEach(async a => { await ctx.ArcAsync(a.Point.X, a.Point.Y, 5, 0, Math.PI * 2); }); await ctx.FillAsync(); await ctx.BeginPathAsync(); enemygrid.GridPoints.Where(a => a.Row == 5).ToList().ForEach(async a => { await ctx.ArcAsync(a.Point.X, a.Point.Y, 5, 0, Math.PI * 2); }); await ctx.FillAsync(); }
protected override async Task OnAfterRenderAsync(bool firstRender) { _stopwatch.Start(); if (firstRender) { _ctx = await _canvas.CreateCanvas2DAsync(); await _ctx.SetFillStyleAsync("green"); await _ctx.SetStrokeStyleAsync("#777777"); await _ctx.SetLineWidthAsync(1); } await _ctx.ClearRectAsync(0, 0, GridSize *Scale, GridSize *Scale); await _ctx.BeginPathAsync(); for (int i = 0; i <= Scale; ++i) { await _ctx.MoveToAsync(GridSize *i, 0); await _ctx.LineToAsync(GridSize *i, GridSize *Scale); await _ctx.MoveToAsync(0, GridSize *i); await _ctx.LineToAsync(GridSize *Scale, GridSize *i); } for (int y = 0; y < Scale; ++y) { for (int x = 0; x < Scale; ++x) { if (_game.GetState(x, y)) { await _ctx.RectAsync(x *GridSize + 1, y *GridSize + 1, GridSize - 2, GridSize - 2); } } } await _ctx.StrokeAsync(); await _ctx.FillAsync(); _stopwatch.Stop(); RenderCostInMilliSecond = _stopwatch.ElapsedMilliseconds; _stopwatch.Reset(); }