Esempio n. 1
0
        public static void drawEyes(NvgContext vg, float x, float y, float w, float h, float mx, float my, float t)
        {
            Paint 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 = vg.LinearGradient(x, y + h * 0.5f, x + w * 0.1f, y + h, new Color(0, 0, 0, 32), new Color(0, 0, 0, 16));
            vg.BeginPath();
            vg.Ellipse(lx + 3.0f, ly + 16.0f, ex, ey);
            vg.Ellipse(rx + 3.0f, ry + 16.0f, ex, ey);
            vg.FillPaint(bg);
            vg.Fill();

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

            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;
            vg.BeginPath();
            vg.Ellipse(lx + dx, ly + dy + ey * 0.25f * (1 - blink), br, br * blink);
            vg.FillColor(new Color(32, 32, 32, 255));
            vg.Fill();

            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;
            vg.BeginPath();
            vg.Ellipse(rx + dx, ry + dy + ey * 0.25f * (1 - blink), br, br * blink);
            vg.FillColor(new Color(32, 32, 32, 255));
            vg.Fill();

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

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