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; }
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 DrawLineAsync(Color color, float lineWidth, int x1, int y1, int x2, int y2) { await this.SetStrokeColor(color); await this.SetLineWidth(lineWidth); await ctx.BeginPathAsync(); await ctx.MoveToAsync(x1, y1); await ctx.LineToAsync(x2, y2); await ctx.StrokeAsync(); }
public void Apply(LineNode lineNode) { _canvas2DContext.BeginPathAsync(); _canvas2DContext.MoveToAsync(lineNode.Start.X, lineNode.Start.Y); _canvas2DContext.LineToAsync(lineNode.End.X, lineNode.End.Y); _canvas2DContext.StrokeAsync(); }
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 async Task Draw(Canvas2DContext context) { await Body[currentIndex].Draw(context); await Head[currentIndex].Draw(context); await context.BeginPathAsync(); await context.StrokeRectAsync(Head[currentIndex].Position.X - Head[currentIndex].ScaledWidth / 2, Head[currentIndex].Position.Y - Head[currentIndex].ScaledHeight / 2, Head[currentIndex].ScaledWidth, Head[currentIndex].ScaledHeight + Body[currentIndex].SourceRectangle.Height *scale.Y); await context.ClosePathAsync(); }
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(); }
private async Task DrawEdgeLine(RenderEdge edge) { await _context.BeginPathAsync(); await _context.MoveToAsync(edge.From.X, edge.From.Y); await _context.LineToAsync(edge.To.X, edge.To.Y); await _context.ClosePathAsync(); await _context.StrokeAsync(); }
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(); }
public async Task Draw(bool vertical) { await ResetCanvas(); if (vertical) { HexGridController.CanvasHeight = Height; HexGridController.CanvasWidth = Width; } else { HexGridController.CanvasHeight = Width; HexGridController.CanvasWidth = Height; } HexGridController.Diameter = Diameter; await Canvas2DContext.SetLineWidthAsync(LineThinkness); await Canvas2DContext.SetStrokeStyleAsync(LineColor); for (var row = 0; row < HexGridController.Rows; row++) { for (var col = 0; col < HexGridController.Columns; col++) { await Canvas2DContext.BeginPathAsync(); var point = HexGridController.GetCoordinates(row, col)[6]; if (vertical) { await Canvas2DContext.MoveToAsync(point.X, point.Y); } else { await Canvas2DContext.MoveToAsync(point.Y, point.X); } for (var pos = 1; pos <= 6; pos++) { point = HexGridController.GetCoordinates(row, col)[pos]; if (vertical) { await Canvas2DContext.LineToAsync(point.X, point.Y); } else { await Canvas2DContext.LineToAsync(point.Y, point.X); } } await Canvas2DContext.StrokeAsync(); } } }
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(); }
public async ValueTask DrawLine(int x1, int y1, int x2, int y2, string color) { await _canvas.SetStrokeStyleAsync(color); await _canvas.BeginPathAsync(); await _canvas.MoveToAsync(x1, y1); await _canvas.LineToAsync(x2, y2); await _canvas.ClosePathAsync(); await _canvas.StrokeAsync(); await _canvas.SetStrokeStyleAsync(""); }
public async ValueTask Render(Canvas2DContext context) { await context.DrawImageAsync(Sprite.SpriteSheet, _transform.Position.X, _transform.Position.Y, Sprite.Size.Width, Sprite.Size.Height); if (DrawBoundingBox) { await context.BeginPathAsync(); await context.SetStrokeStyleAsync($"rgb(255,255,0)"); await context.SetLineWidthAsync(3); await context.StrokeRectAsync(_transform.BoundingBox.X, _transform.BoundingBox.Y, _transform.BoundingBox.Width, _transform.BoundingBox.Height); } }
public async ValueTask DrawLine(Vector2 from, Vector2 to, Color color) { var f = from + _origin.ToVector2(); var t = to + _origin.ToVector2(); await _canvas2DContext.BeginPathAsync(); await _canvas2DContext.SetStrokeStyleAsync($"rgb({color.R},{color.G},{color.B})"); await _canvas2DContext.SetLineWidthAsync(3); await _canvas2DContext.SetLineCapAsync(LineCap.Round); await _canvas2DContext.MoveToAsync(f.X, f.Y); await _canvas2DContext.LineToAsync(t.X, t.Y); await _canvas2DContext.StrokeAsync(); }
public async ValueTask Render(GameContext game, Canvas2DContext context) { var tmpW = context.LineWidth; var tmpS = context.StrokeStyle; await context.BeginPathAsync(); await context.SetStrokeStyleAsync("rgb(255,255,0)"); await context.SetLineWidthAsync(3); await context.StrokeRectAsync(_bounds.X, _bounds.Y, _bounds.Width, _bounds.Height); await context.SetStrokeStyleAsync(tmpS); await context.SetLineWidthAsync(tmpW); }
/// <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(); }