예제 #1
0
        static void DrawEyes(NanoVGContext vg, float x, float y, float w, float h, float mx, float my, float t)
        {
            NVGPaint gloss, bg;
            float    ex = w * 0.23f;
            float    ey = h * 0.5f;
            float    lx = x + ex;
            float    ly = y + ey;
            float    rx = x + w - ex;
            float    ry = y + ey;
            float    dx, dy, d;
            float    br    = (ex < ey ? ex : ey) * 0.5f;
            float    blink = 1 - (float)(Math.Pow(Math.Sin(t * 0.5f), 200) * 0.8f);

            bg = NVG.LinearGradient(vg, x, y + h * 0.5f, x + w * 0.1f, y + h, NVG.RGBA(0, 0, 0, 32), NVG.RGBA(0, 0, 0, 16));
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, lx + 3.0f, ly + 16.0f, ex, ey);
            NVG.Ellipse(vg, rx + 3.0f, ry + 16.0f, ex, ey);
            NVG.FillPaint(vg, bg);
            NVG.Fill(vg);

            bg = NVG.LinearGradient(vg, x, y + h * 0.25f, x + w * 0.1f, y + h, NVG.RGBA(220, 220, 220, 255), NVG.RGBA(128, 128, 128, 255));
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, lx, ly, ex, ey);
            NVG.Ellipse(vg, rx, ry, ex, ey);
            NVG.FillPaint(vg, bg);
            NVG.Fill(vg);

            dx = (mx - rx) / (ex * 10);
            dy = (my - ry) / (ey * 10);
            d  = (float)Math.Sqrt(dx * dx + dy * dy);
            if (d > 1.0f)
            {
                dx /= d; dy /= d;
            }
            dx *= ex * 0.4f;
            dy *= ey * 0.5f;
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, lx + dx, ly + dy + ey * 0.25f * (1 - blink), br, br * blink);
            NVG.FillColor(vg, NVG.RGBA(32, 32, 32, 255));
            NVG.Fill(vg);

            dx = (mx - rx) / (ex * 10);
            dy = (my - ry) / (ey * 10);
            d  = (float)Math.Sqrt(dx * dx + dy * dy);
            if (d > 1.0f)
            {
                dx /= d; dy /= d;
            }
            dx *= ex * 0.4f;
            dy *= ey * 0.5f;
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, rx + dx, ry + dy + ey * 0.25f * (1 - blink), br, br * blink);
            NVG.FillColor(vg, NVG.RGBA(32, 32, 32, 255));
            NVG.Fill(vg);

            gloss = NVG.RadialGradient(vg, lx - ex * 0.25f, ly - ey * 0.5f, ex * 0.1f, ex * 0.75f, NVG.RGBA(255, 255, 255, 128), NVG.RGBA(255, 255, 255, 0));
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, lx, ly, ex, ey);
            NVG.FillPaint(vg, gloss);
            NVG.Fill(vg);

            gloss = NVG.RadialGradient(vg, rx - ex * 0.25f, ry - ey * 0.5f, ex * 0.1f, ex * 0.75f, NVG.RGBA(255, 255, 255, 128), NVG.RGBA(255, 255, 255, 0));
            NVG.BeginPath(vg);
            NVG.Ellipse(vg, rx, ry, ex, ey);
            NVG.FillPaint(vg, gloss);
            NVG.Fill(vg);
        }