protected Action <MouseEventArgs> SetStrokeColour(string colour) { return(async _ => { actualColor = colour; //Console.WriteLine($"set color: {colour}"); await ctx.SetStrokeStyleAsync(colour); await ctx.SetfontAsync(canvasFont); }); }
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(""); }
/// <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 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); }
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(); }
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { windowSize.Height = 400; windowSize.Width = 400; Console.WriteLine($" canavsID: {canvasID}, {windowSize.Height}, {windowSize.Width}"); ctx = new Canvas2DContext(JSRuntime, canvas); ClockTask = RunClock(); await this.ctx.DrawBackground(windowSize.Height / 2); await ctx.SetStrokeStyleAsync(actualColor); await ctx.SetfontAsync(canvasFont); } }
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(); }
internal async Task SetStrokeColor(Color color) { await ctx.SetStrokeStyleAsync(color.AsHtml); }