Ejemplo n.º 1
0
        private void DrawGraph(float x, float y, float w, float h, float t)
        {
            float dx = w / 5.0f;

            Span <float> samples = stackalloc float[]
            {
                (1 + MathF.Sin(t * 1.2345f + MathF.Cos(t * 0.33457f) * 0.44f)) * 0.5f,
                (1 + MathF.Sin(t * 0.68363f + MathF.Cos(t * 1.3f) * 1.55f)) * 0.5f,
                (1 + MathF.Sin(t * 1.1642f + MathF.Cos(t * 0.33457f) * 1.24f)) * 0.5f,
                (1 + MathF.Sin(t * 0.56345f + MathF.Cos(t * 1.63f) * 0.14f)) * 0.5f,
                (1 + MathF.Sin(t * 1.6245f + MathF.Cos(t * 0.254f) * 0.3f)) * 0.5f,
                (1 + MathF.Sin(t * 0.345f + MathF.Cos(t * 0.03f) * 0.6f)) * 0.5f
            };

            Span <float> sx = stackalloc float[6];
            Span <float> sy = stackalloc float[6];

            for (int i = 0; i < 6; i++)
            {
                sx[i] = x + i * dx;
                sy[i] = y + h * samples[i] * 0.8f;
            }

            Paint bg = Paint.LinearGradient(x, y, x, y + h, new Colour(0, 160, 192, 0), new Colour(0, 160, 192, 64));

            _nvg.BeginPath();
            _nvg.MoveTo(sx[0], sy[0]);
            for (int i = 1; i < 6; i++)
            {
                _nvg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i]);
            }
            _nvg.LineTo(x + w, y + h);
            _nvg.LineTo(x, y + h);
            _nvg.FillPaint(bg);
            _nvg.Fill();

            _nvg.BeginPath();
            _nvg.MoveTo(sx[0], sy[0] + 2);
            for (int i = 1; i < 6; i++)
            {
                _nvg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1] + 2, sx[i] - dx * 0.5f, sy[i] + 2, sx[i], sy[i] + 2);
            }
            _nvg.StrokeColour(new Colour(0, 0, 0, 32));
            _nvg.StrokeWidth(3.0f);
            _nvg.Stroke();

            _nvg.BeginPath();
            _nvg.MoveTo(sx[0], sy[0]);
            for (int i = 1; i < 6; i++)
            {
                _nvg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i]);
            }
            _nvg.StrokeColour(new Colour(0, 160, 192, 255));
            _nvg.StrokeWidth(3.0f);
            _nvg.Stroke();

            for (int i = 0; i < 6; i++)
            {
                bg = Paint.RadialGradient(sx[i], sy[i] + 2, 3.0f, 8.0f, new Colour(0, 0, 0, 32), new Colour(0, 0, 0, 0));
                _nvg.BeginPath();
                _nvg.Rect(sx[i] - 10, sy[i] - 10 + 2, 20, 20);
                _nvg.FillPaint(bg);
                _nvg.Fill();
            }

            _nvg.BeginPath();
            for (int i = 0; i < 6; i++)
            {
                _nvg.Circle(sx[i], sy[i], 4.0f);
            }
            _nvg.FillColour(new Colour(0, 160, 192, 255));
            _nvg.Fill();
            _nvg.BeginPath();
            for (int i = 0; i < 6; i++)
            {
                _nvg.Circle(sx[i], sy[i], 2.0f);
            }
            _nvg.FillColour(new Colour(220, 220, 220, 255));
            _nvg.Fill();
        }