예제 #1
0
        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();
        }
예제 #2
0
        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();
        }
        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();
        }
예제 #4
0
        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;
        }
예제 #5
0
 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();
 }
예제 #6
0
        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();
        }
예제 #7
0
        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();
                }
            }
        }
예제 #8
0
        /// <summary>
        /// 画时针
        /// </summary>
        /// <param name="hour">小时</param>
        /// <param name="radius">半径</param>
        /// <returns></returns>
        private async Task DrawHourHandAsync(int hour, double radius)
        {
            await _context.SaveAsync();

            await _context.TranslateAsync(radius, radius);

            double theta = (hour - 3) * 2 * Math.PI / 12;
            await _context.RotateAsync((float)theta);

            await _context.BeginPathAsync();

            await _context.MoveToAsync(-15, -5);

            await _context.LineToAsync(-15, 5);

            await _context.LineToAsync(radius * 0.6, 1);

            await _context.LineToAsync(radius * 0.6, -1);

            await _context.FillAsync();

            await _context.RestoreAsync();
        }
예제 #9
0
        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("");
        }
예제 #10
0
        public static async Task DrawBar(this Canvas2DContext con, int barValue, string color, int xPos, int chartHeight)
        {
            await con.MoveToAsync(barWidth + xPos + spaceX, chartHeight - spaceY);

            await con.LineToAsync(barWidth + xPos + spaceX, chartHeight - spaceY);

            await con.StrokeAsync();

            int barHeight = -barValue * 2;

            await con.SetFillStyleAsync(color);

            await con.FillRectAsync(xPos + spaceX, chartHeight - spaceY - 1, barWidth, barHeight);

            await con.FillTextAsync(barValue.ToString(), xPos + spaceX + 5, chartHeight - spaceY + barHeight - 2);

            await con.SetFillStyleAsync(COLOR.Black);
        }
예제 #11
0
        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();
        }