Exemplo n.º 1
0
        public static void drawGraph(NvgContext vg, float x, float y, float w, float h, float t)
        {
            Paint bg;

            float[] samples = new float[6];
            float[] sx      = new float[6], sy = new float[6];
            float   dx      = w / 5.0f;
            int     i;

            samples[0] = (1 + (float)Math.Sin(t * 1.2345f + (float)Math.Cos(t * 0.33457f) * 0.44f)) * 0.5f;
            samples[1] = (1 + (float)Math.Sin(t * 0.68363f + (float)Math.Cos(t * 1.3f) * 1.55f)) * 0.5f;
            samples[2] = (1 + (float)Math.Sin(t * 1.1642f + (float)Math.Cos(t * 0.33457) * 1.24f)) * 0.5f;
            samples[3] = (1 + (float)Math.Sin(t * 0.56345f + (float)Math.Cos(t * 1.63f) * 0.14f)) * 0.5f;
            samples[4] = (1 + (float)Math.Sin(t * 1.6245f + (float)Math.Cos(t * 0.254f) * 0.3f)) * 0.5f;
            samples[5] = (1 + (float)Math.Sin(t * 0.345f + (float)Math.Cos(t * 0.03f) * 0.6f)) * 0.5f;

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

            // Graph background
            bg = vg.LinearGradient(x, y, x, y + h, new Color(0, 160, 192, 0), new Color(0, 160, 192, 64));
            vg.BeginPath();
            vg.MoveTo(sx[0], sy[0]);
            for (i = 1; i < 6; i++)
            {
                vg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1], sx[i] - dx * 0.5f, sy[i], sx[i], sy[i]);
            }
            vg.LineTo(x + w, y + h);
            vg.LineTo(x, y + h);
            vg.FillPaint(bg);
            vg.Fill();

            // Graph line
            vg.BeginPath();
            vg.MoveTo(sx[0], sy[0] + 2);
            for (i = 1; i < 6; i++)
            {
                vg.BezierTo(sx[i - 1] + dx * 0.5f, sy[i - 1] + 2, sx[i] - dx * 0.5f, sy[i] + 2, sx[i], sy[i] + 2);
            }
            vg.StrokeColor(new Color(0, 0, 0, 32));
            vg.StrokeWidth(3.0f);
            vg.Stroke();

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

            // Graph sample pos
            for (i = 0; i < 6; i++)
            {
                bg = vg.RadialGradient(sx[i], sy[i] + 2, 3.0f, 8.0f, new Color(0, 0, 0, 32), new Color(0, 0, 0, 0));
                vg.BeginPath();
                vg.Rect(sx[i] - 10, sy[i] - 10 + 2, 20, 20);
                vg.FillPaint(bg);
                vg.Fill();
            }

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

            vg.StrokeWidth(1.0f);
        }