public override void Run()
        {
            string ptstr = @"{\p1}m 0 0 l 1 0 1 1 0 1";

            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            forceCurve = new CompositeCurve {
                MinT = 0, MaxT = 30
            };
            double lastag = 0;

            for (double time = forceCurve.MinT; time <= forceCurve.MaxT; time += 1)
            {
                double ag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                while (Math.Abs(ag - lastag) < Math.PI * 0.5 || Math.Abs(ag - lastag) > Math.PI * 1.5)
                {
                    ag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                }
                lastag = ag;
                //ag = 0;
                double x = 1000.0 * Math.Cos(ag);
                double y = 600.0 * Math.Sin(ag);
                forceCurve.AddCurve(time, time + 1, new Line {
                    X0 = x, Y0 = y, X1 = 0, Y1 = 0, Acc = 0.7
                });
                //forceCurve.AddCurve(time, time + 1, new Line { X0 = 0, Y0 = 0, X1 = 0, Y1 = 0 });
            }

            NumberPerSecond = 100;
            XXParticleSystem xxps = new XXParticleSystem();

            xxps.Emitter                = this;
            xxps.ForceField             = this;
            xxps.StartTime              = 0;
            xxps.EndTime                = 3;
            xxps.InterpolationPrecision = 0.04;
            xxps.Resistance             = 0.03;
            xxps.Repulsion              = -2200;
            xxps.Gravity                = 0;
            xxps.GravityPosition        = this;
            List <KeyValuePair <XXParticleElement, List <ASSPointF> > > result = xxps.RenderPoint();

            foreach (KeyValuePair <XXParticleElement, List <ASSPointF> > pair in result)
            {
                string s = CreatePolygon(rnd, 5, 10, 6);
                foreach (ASSPointF pt in pair.Value)
                {
                    ass_out.AppendEvent(0, "pt", pt.T, pt.T + xxps.InterpolationPrecision,
                                        pos(pt.X, pt.Y) + a(1, "22") + a(3, "77") + blur(2) + bord(1.5) + c(3, "532BFF") +
                                        s);
                    continue;
                    ass_out.AppendEvent(0, "pt", pt.T, pt.T + xxps.InterpolationPrecision,
                                        pos(pt.X, pt.Y) + a(1, "00") +
                                        ptstr);
                    continue;
                    ASSPointF force = forceCurve.GetPointF(pt.T);
                    ass_out.AppendEvent(0, "pt", pt.T, pt.T + xxps.InterpolationPrecision,
                                        pos(0, 0) + an(7) + a(1, "00") + fs(16) +
                                        string.Format("{0}, {1}", force.X, force.Y));
                }
            }

            ass_out.SaveFile(OutFileName);
        }
Example #2
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool isJp = true;
                this.MaskStyle = isJp ?
                                 "Style: Default,EPSON 行書体M,26,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,0,0,5,0,0,0,128" :
                                 "Style: Default,仿宋,36,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,0,0,5,0,0,0,1";
                this.FontHeight = isJp ? 26 : 30;
                int jEv = isJp ? iEv : iEv;
                //if (jEv != 0) continue;
                ASSEvent        ev         = ass_in.Events[iEv];
                List <KElement> kelems     = ev.SplitK(true);
                int             totalWidth = GetTotalWidth(ev);
                int             x0         = (PlayResX - MarginLeft - MarginRight - totalWidth) / 2 + MarginLeft;
                int             y0         = (isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                int             kSum       = 0;
                int             x0_start   = x0;
                string          outlines   = "";
                List <KeyValuePair <double, ASSPoint> > textpath = new List <KeyValuePair <double, ASSPoint> >();
                string MainColor = "112836";
                if (iEv >= 8)
                {
                    MainColor = "C5A8A0";
                }
                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke     = kelems[iK];
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int x     = x0 + this.FontSpace + sz.Width / 2;
                    int y     = y0 + FontHeight / 2;
                    int x_an7 = x0;
                    int y_an7 = y0;
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    StringMask mask    = GetMask(ke.KText, x, y);
                    string     evStyle = isJp ? "op_jp" : "op_cn";

                    /*
                     * string outlineFontname = isJp ? "EPSON 行書体M" : "方正准圆_GBK";
                     * int outlineEncoding = isJp ? 128 : 1;
                     * int xoffset = isJp ? 0 : -1;
                     * if (isJp && ke.KText[0] == '中') xoffset = -2;
                     * string outlineString = GetOutline(x - sz.Width / 2 + xoffset, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, 179);
                     * outlines += outlineString;
                     * */

                    double t0 = ev.Start - 0.5 + iK * 0.1;
                    double t1 = t0 + 0.5;
                    double t2 = kStart;
                    double t3 = ev.End - 0.5 + iK * 0.1;
                    double t4 = t3 + 0.5;

                    ass_out.AppendEvent(50, evStyle, t0, t4,
                                        fad(t1 - t0, t4 - t3) + pos(x, y) +
                                        a(1, "00") + c(1, MainColor) +
                                        ke.KText);
                    ass_out.AppendEvent(49, evStyle, t0, t4,
                                        fad(t1 - t0, t4 - t3) + pos(x + 1.5, y + 1.5) +
                                        a(1, "00") + c(1, "000000") + blur(1) +
                                        ke.KText);
                    ass_out.AppendEvent(60, evStyle, t2, t2 + 0.5,
                                        fad(0, 0.42) + pos(x, y) +
                                        a(1, "00") + c(1, "FFFFFF") +
                                        ke.KText);
                    ass_out.AppendEvent(60, evStyle, t2, t2 + 1,
                                        pos(x + 1.5, y + 1.5) +
                                        a(1, "00") + c(1, "FFFFFF") + blur(1) +
                                        t(0, 1, 0.8, a(1, "FF").t()) +
                                        ke.KText);
                    ass_out.AppendEvent(60, evStyle, t2, t2 + 1,
                                        fad(0, 0.42) +
                                        pos(x, y) +
                                        a(1, "FF") + a(3, "BB") + c(3, "FFFFFF") +
                                        blur(3) + bord(2.5) +
                                        t(0, 1, 0.8, a(3, "FF").t()) +
                                        ke.KText);

                    textpath.Add(new KeyValuePair <double, ASSPoint>(kStart, new ASSPoint {
                        X = x, Y = y, Start = kStart, End = kEnd
                    }));

                    if (iEv == 1)
                    {
                        for (int i = 0; i < 100; i++)
                        {
                            double ptt0 = Common.RandomDouble(rnd, t3, t4);
                            double ptt1 = ptt0 + Common.RandomDouble(rnd, 0.5, 1);
                            double ptx0 = Common.RandomDouble(rnd, x - 17, x + 17) - 25;
                            double pty0 = Common.RandomDouble(rnd, y - 17, y + 17);
                            double ptx1 = ptx0 + Common.RandomDouble(rnd, 30, 50) * 1.4;
                            double pty1 = pty0 + Common.RandomDouble(rnd, 5, 30) * Common.RandomSig(rnd);
                            int    tmp1 = Common.RandomInt(rnd, 0, 359);
                            ass_out.AppendEvent(70, "pt", ptt0, ptt1,
                                                move(ptx0, pty0, ptx1, pty1) + a(1, "00") + blur(0.5) + a(4, "DD") + c(4, "000000") + shad(2) +
                                                fad(0, 0.5) +
                                                //c(1, Common.RandomBool(rnd, 0.9) ? MainColor : Common.scaleColor(MainColor, "FFFFFF", 0.2)) +
                                                c(1, Common.scaleColor(MainColor, "FFFFFF", Common.RandomDouble(rnd, 0, 0.15))) +
                                                frz(tmp1) +
                                                CreatePolygon(rnd, 15, 23, 6));
                        }
                    }
                    if (iEv >= 2 && iEv <= 4)
                    {
                        for (int i = 0; i < (kEnd - kStart) * 30; i++)
                        {
                            double ptt0 = Common.RandomDouble(rnd, kStart, kEnd);
                            double ptt1 = ptt0 + Common.RandomDouble(rnd, 0.5, 1) * 2;
                            double ptx0 = Common.RandomDouble(rnd, x - 13, x + 13);
                            double pty0 = Common.RandomDouble(rnd, y - 13, y + 13);
                            double ptx1 = ptx0 - Common.RandomDouble(rnd, 30, 100) * 1.4;
                            double pty1 = pty0 + Common.RandomDouble(rnd, 20, 45);
                            int    tmp1 = Common.RandomInt(rnd, 0, 359);
                            ass_out.AppendEvent(70, "pt", ptt0, ptt1,
                                                move(ptx0, pty0, ptx1, pty1) + a(1, "00") + blur(0.5) + a(4, "DD") + c(4, "000000") + shad(2) +
                                                fad(0, 0.5) +
                                                //c(1, Common.RandomBool(rnd, 0.9) ? MainColor : Common.scaleColor(MainColor, "FFFFFF", 0.2)) +
                                                c(1, Common.scaleColor(MainColor, "FFFFFF", Common.RandomDouble(rnd, 0, 0.15))) +
                                                frz(tmp1) +
                                                CreatePolygon(rnd, 15, 23, 6));
                        }
                    }
                }

                if (iEv >= 5)// && iEv <= 7)
                {
                    for (int i = 0; i < textpath.Count - 1; i++)
                    {
                        if (textpath[i].Value.End < textpath[i + 1].Value.Start)
                        {
                            textpath[i].Value.End = textpath[i + 1].Value.Start;
                        }
                    }
                    textpath[textpath.Count - 1].Value.End = ev.End;

                    emitterList = new List <ASSPointF>();
                    foreach (KeyValuePair <double, ASSPoint> pair in textpath)
                    {
                        emitterList.Add(new ASSPointF
                        {
                            Start = pair.Value.Start,
                            End   = pair.Value.End,
                            X     = pair.Value.X + Common.RandomDouble(rnd, -20, 20),
                            Y     = pair.Value.Y + Common.RandomDouble(rnd, -20, 20)
                        });
                    }

                    forceCurve = new CompositeCurve {
                        MinT = ev.Start, MaxT = ev.End + 10
                    };
                    double lastag = 0;
                    for (double time = forceCurve.MinT; time <= forceCurve.MaxT; time += 0.7)
                    {
                        double ag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                        while (Math.Abs(ag - lastag) < Math.PI * 0.5 || Math.Abs(ag - lastag) > Math.PI * 1.5)
                        {
                            ag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                        }
                        lastag = ag;
                        double x = 1500.0 * Math.Cos(ag);
                        double y = 800.0 * Math.Sin(ag);
                        forceCurve.AddCurve(time, time + 0.7, new Line {
                            X0 = x, Y0 = y, X1 = 0, Y1 = 0, Acc = 0.7
                        });
                    }

                    NumberPerSecond = 110;
                    XXParticleSystem xxps = new XXParticleSystem();
                    xxps.Emitter                = this;
                    xxps.ForceField             = this;
                    xxps.StartTime              = ev.Start;
                    xxps.EndTime                = ev.End;
                    xxps.InterpolationPrecision = 0.03;
                    xxps.Resistance             = 0.04;
                    xxps.Repulsion              = -3600;
                    xxps.Gravity                = 0;
                    xxps.GravityPosition        = this;

                    xxps.InterpolationPrecision = 0.01;
                    List <KeyValuePair <XXParticleElement, List <string> > > result = xxps.RenderT();
                    foreach (KeyValuePair <XXParticleElement, List <string> > pair in result)
                    {
                        string s     = CreatePolygon(rnd, 12, 12, 4);
                        string ptstr = @"{\p1}m 0 0 l 1 0 1 1 0 1";
                        string ptcol = "532BFF";
                        ass_out.AppendEvent(70, "pt", pair.Key.Born, pair.Key.Born + pair.Key.Life,
                                            pos(-100, -100) +
                                            pair.Value[1] +
                                            ptstr + "\\N" + r() +
                                            pair.Value[0] +
                                            ptstr + r() +
                                            a(1, "00") + blur((iEv <= 7) ? 0.6 : 0.8) + a(4, "DD") + c(4, "000000") + shad(2) +
                                            fad(0, 0.5) +
                                            c(1, Common.scaleColor(MainColor, "FFFFFF", Common.RandomDouble(rnd, 0, 0.15))) +
                                            CreatePolygon(rnd, 15, 23, 6));
                    }
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool isJp = iEv <= 6;
                //if (!isJp || iEv < 4 || iEv > 4) continue;
                this.MaskStyle = isJp ?
                                 "Style: Default,DFMincho-UB,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128" :
                                 "Style: Default,汉仪粗宋繁,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,1,0,0,0,100,100,0,0,0,0,0,5,0,0,0,134";
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(!isJp);
                int             x0     = MarginLeft;
                if ((isJp && iEv >= 4) || (!isJp && iEv - 7 >= 4))
                {
                    x0 = PlayResX - MarginRight - GetTotalWidth(ev);
                }
                int y0   = (isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                int kSum = 0;

                List <KeyValuePair <double, ASSPoint> > textpath = new List <KeyValuePair <double, ASSPoint> >();

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    //if (iK > 0) break;
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    string   evStyle         = isJp ? "jp" : "cn";
                    string   outlineFontname = isJp ? "DFMincho-UB" : "汉仪粗宋繁";
                    int      outlineEncoding = isJp ? 128 : 134;
                    KElement ke = kelems[iK];
                    Size     sz = GetSize(ke.KText);
                    if (ke.KText[0] == 'く')
                    {
                        x0 += 2;
                    }
                    double kStart = ev.Start + kSum * 0.01;
                    double kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x     = x0 + this.FontSpace + sz.Width / 2;
                    int        y     = y0 + FontHeight / 2;
                    int        x_an7 = x0 + 2;
                    int        y_an7 = y0;
                    StringMask mask  = GetMask(ke.KText, x, y);
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    string outlineString = GetOutline(x - FontHeight / 2, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, 38, 0, 262);

                    if (!isJp)
                    {
                        y += 2;
                    }

                    textpath.Add(new KeyValuePair <double, ASSPoint>(kStart, new ASSPoint {
                        X = x, Y = y, Start = kStart, End = kEnd
                    }));

                    double t0 = ev.Start - 0.5 + iK * 0.07;
                    double t1 = t0 + 0.5;
                    double t2 = kStart;
                    double t3 = kEnd;
                    double t4 = ev.End - 0.6 + iK * 0.07;
                    double t5 = t4 + 0.5;

                    {
                        string red = "1A037C";
                        red = "3B1FB6";
                        string aoi = "9D3653";

                        string scol = iEv <= 1 ? red : aoi;
                        if (iEv >= 4)
                        {
                            scol = red;
                        }

                        if (isJp)
                        {
                            ass_out.AppendEvent(51, "pt", t2, t2 + 1,
                                                pos(0, 0) + fad(0, 0.9) +
                                                a(1, "00") + a(3, "77") + blur(5) + bord(5) + t(bord(0).t()) +
                                                p(4) + outlineString);
                        }
                        ass_out.AppendEvent(40, "pt", t0, t5,
                                            pos(1, 1) + fad(0.5, 0.5) +
                                            a(1, "00") + blur(1.3) + c(1, "000000") +
                                            p(4) + outlineString);

                        if (true)
                        {
                            double lastptx0 = 0;
                            double lastpty0 = 0;
                            bool   first    = true;

                            for (double ti = t0 - 1 + Common.RandomDouble(rnd, -0.3, 0.3); ti <= t5 - 1.5; ti += Common.RandomDouble(rnd, 1.2, 1.65))
                            {
                                double ptt0 = ti;
                                double ptt1 = ptt0 + 3;
                                double ptx0 = Common.RandomDouble(rnd, x - 20, x + 20);
                                double pty0 = Common.RandomDouble(rnd, y - 20, y + 20);

                                if (!first)
                                {
                                    for (int i = 0; i < 2; i++)
                                    {
                                        double ptx0_tmp = Common.RandomDouble(rnd, x - 20, x + 20);
                                        double pty0_tmp = Common.RandomDouble(rnd, y - 20, y + 20);
                                        if (Common.GetDistance(lastptx0, lastpty0, ptx0, pty0) < Common.GetDistance(lastptx0, lastpty0, ptx0_tmp, pty0_tmp))
                                        {
                                            ptx0 = ptx0_tmp;
                                            pty0 = pty0_tmp;
                                        }
                                    }
                                }
                                first    = false;
                                lastptx0 = ptx0;
                                lastpty0 = pty0;

                                string ptcol = "FFFFFF";
                                double lumsz = 15 + Common.GetDistance(x, y, ptx0, pty0) * 0.5;
                                if (ptt0 >= kStart - 1 && ptt0 <= kEnd - 1)
                                {
                                    lumsz += 0;
                                }
                                //if (iEv <= 3)
                                if (isJp)
                                {
                                    if (ptt0 >= t2)
                                    {
                                        ptcol = scol;
                                    }
                                }

                                string ts0 = "";
                                //if (iEv <= 3)
                                if (isJp)
                                {
                                    if (ptt0 < t2 && ptt1 > t2)
                                    {
                                        ts0 = t(t2 - ptt0 - 0.01, t2 - ptt0, c(1, scol).t() + c(3, scol).t());
                                    }
                                }

                                int dup = 1;
                                if ((isJp && iEv >= 4) || (!isJp && iEv - 7 >= 4))
                                {
                                    dup = 2;
                                }

                                while (dup-- > 0)
                                {
                                    ass_out.AppendEvent(50, "pt", ptt0, ptt1,
                                                        pos(ptx0, pty0) + clip(4, outlineString) + org(x, y) + t(frz(Common.RandomSig(rnd) * Common.RandomInt(rnd, 80, 120)).t()) +
                                                        fad(0.8, 0.8) + t(0, ptt1 - ptt0, bord(lumsz).t() + blur(lumsz).t()) +
                                                        a(1, "44") + a(3, "44") + c(1, ptcol) + c(3, ptcol) +
                                                        ts0 +
                                                        t((ptt1 - ptt0) * 0.7, ptt1, c(1, "000000").t() + c(3, "000000").t()) +
                                                        p(1) + "m 0 0 l 1 0 1 1 0 1");
                                }
                            }
                        }
                    }

                    if (!isJp)
                    {
                        continue;
                    }

                    if (iEv <= 3)
                    {
                        for (int i = 0; i < (kEnd - kStart) * 7; i++)
                        {
                            double ptx0 = Common.RandomDouble(rnd, x - 20, x + 20);
                            double pty0 = Common.RandomDouble(rnd, y - 5, y + 20);
                            double ptx1 = Common.RandomDouble(rnd, ptx0 - 150, ptx0 - 250);
                            double pty1 = Common.RandomDouble(rnd, pty0 - 30, pty0 - 80);
                            double ptt0 = Common.RandomDouble(rnd, kStart, kEnd) - 0.3;
                            double ptt1 = ptt0 + 5;

                            double posx = 0, posy = 0;
                            if (ptx0 < 0 || ptx1 < 0)
                            {
                                posx  = Math.Min(ptx0, ptx1);
                                ptx0 -= posx;
                                ptx1 -= posx;
                            }
                            if (pty0 < 0 || pty1 < 0)
                            {
                                posy  = Math.Min(pty0, pty1);
                                pty0 -= posy;
                                pty1 -= posy;
                            }
                            string moveStringX  = fscx((int)(ptx0 * 100)) + t(0, 5, 3, fscx((int)(ptx1 * 100)).t());
                            string moveStringY  = fscy((int)(pty0 * 100)) + t(0, 5, 0.6, fscy((int)(pty1 * 100)).t());
                            string splashString = "";
                            for (double ti = 0; ti <= ptt1 - ptt0; ti += 0.8)
                            {
                                splashString += t(ti + 0, ti + 0.4, a(1, "FF").t() + a(3, "FF").t()) + t(ti + 0.4, ti + 0.8, a(1, "22").t() + a(3, "44").t());
                            }

                            string ptstr  = @"{\p1}m 0 0 l 1 0 1 1 0 1";
                            string par    = CreatePolygon(rnd, 5, 10, 6);
                            string parcol = "EC3667";
                            if (iEv <= 1)
                            {
                                parcol = "532BFF";
                            }

                            for (int j = 0; j < 1; j++)
                            {
                                ass_out.AppendEvent(12, "pt", ptt0 + j * 0.1, ptt1 + j * 0.1,
                                                    pos(posx, posy) +
                                                    moveStringY +
                                                    ptstr + "\\N" + r() +
                                                    moveStringX +
                                                    ptstr + r() +
                                                    fad(0, 0.5) + pos(0, 0) +
                                                    a(1, "22") + a(3, "44") + blur(1.5) + bord(1.5) + c(3, parcol) +
                                                    splashString +
                                                    par);
                            }
                        }
                    }
                }

                if (!isJp)
                {
                    continue;
                }

                //continue;

                if (iEv >= 4)
                {
                    for (int i = 0; i < textpath.Count - 1; i++)
                    {
                        if (textpath[i].Value.End < textpath[i + 1].Value.Start)
                        {
                            textpath[i].Value.End = textpath[i + 1].Value.Start;
                        }
                    }
                    textpath[textpath.Count - 1].Value.End = ev.End;

                    emitterList = new List <ASSPointF>();
                    foreach (KeyValuePair <double, ASSPoint> pair in textpath)
                    {
                        emitterList.Add(new ASSPointF
                        {
                            Start = pair.Value.Start,
                            End   = pair.Value.End,
                            X     = pair.Value.X + Common.RandomDouble(rnd, -20, 20),
                            Y     = pair.Value.Y + Common.RandomDouble(rnd, -20, 20)
                        });
                    }

                    forceCurve = new CompositeCurve {
                        MinT = ev.Start, MaxT = ev.End + 10
                    };
                    double lastag = 0;
                    for (double time = forceCurve.MinT; time <= forceCurve.MaxT; time += 0.7)
                    {
                        double ag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                        while (Math.Abs(ag - lastag) < Math.PI * 0.5 || Math.Abs(ag - lastag) > Math.PI * 1.5)
                        {
                            ag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                        }
                        lastag = ag;
                        double x = 1500.0 * Math.Cos(ag);
                        double y = 800.0 * Math.Sin(ag);
                        forceCurve.AddCurve(time, time + 0.7, new Line {
                            X0 = x, Y0 = y, X1 = 0, Y1 = 0, Acc = 0.7
                        });
                    }

                    NumberPerSecond = 90;
                    XXParticleSystem xxps = new XXParticleSystem();
                    xxps.Emitter                = this;
                    xxps.ForceField             = this;
                    xxps.StartTime              = ev.Start;
                    xxps.EndTime                = ev.End;
                    xxps.InterpolationPrecision = 0.03;
                    xxps.Resistance             = 0.04;
                    xxps.Repulsion              = -3600;
                    xxps.Gravity                = 0;
                    xxps.GravityPosition        = this;

                    xxps.InterpolationPrecision = 0.01;
                    List <KeyValuePair <XXParticleElement, List <string> > > result = xxps.RenderT();
                    foreach (KeyValuePair <XXParticleElement, List <string> > pair in result)
                    {
                        string s     = CreatePolygon(rnd, 12, 12, 4);
                        string ptstr = @"{\p1}m 0 0 l 1 0 1 1 0 1";
                        string ptcol = "532BFF";
                        ass_out.AppendEvent(100, "pt", pair.Key.Born, pair.Key.Born + pair.Key.Life,
                                            pos(-100, -100) +
                                            pair.Value[1] +
                                            ptstr + "\\N" + r() +
                                            pair.Value[0] +
                                            ptstr + r() +
                                            a(1, "22") + a(3, "77") + blur(2.5) + bord(2) + c(3, ptcol) +
                                            s);
                    }

                    /*
                     * List<KeyValuePair<XXParticleElement, List<ASSPointF>>> result = xxps.RenderPoint();
                     * foreach (KeyValuePair<XXParticleElement, List<ASSPointF>> pair in result)
                     * {
                     *  string s = CreatePolygon(rnd, 12, 12, 4);
                     *  foreach (ASSPointF pt in pair.Value)
                     *  {
                     *      pt.T -= 0.3;
                     *      string ptcol = "532BFF";
                     *      ass_out.AppendEvent(100, "pt", pt.T, pt.T + xxps.InterpolationPrecision,
                     *          pos(pt.X, pt.Y) + a(1, "22") + a(3, "77") + blur(2.5) + bord(2) + c(3, ptcol) +
                     *          s);
                     *  }
                     * }
                     * */
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
Example #4
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            /*
             * foreach (Beat bt in GetBeats())
             *  ass_out.AppendEvent(0, "op_jp", bt.Time, bt.Time + 0.4,
             *      pos(50, 30) + a(1, "00") + c(3, "00") + bord(2) + blur(2) + fad(0, 0.3) +
             *      bt.Id.ToString());
             * */

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                if (iEv == 19)
                {
                    continue;
                }
                bool isJp = iEv <= 9 || iEv == 19;
                int  jEv  = (iEv >= 10) ? iEv - 10 : iEv;
                if (iEv != 0)
                {
                    continue;
                }
                //if (!isJp) continue;
                //if (iEv != 0 && iEv != 10) continue;
                this.FontHeight = isJp ? 23 : 25;
                this.FontSpace  = isJp ? 1 : 1;
                this.MaskStyle  = isJp ?
                                  "Style: Default,DFSoGei-W7,23,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,0,0,5,0,0,0,128" :
                                  "Style: Default,方正综艺_GBK,25,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,0,0,5,0,0,0,1";
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(true);
                int             x0     = (PlayResX - MarginLeft - MarginRight - GetTotalWidth(ev)) / 2 + MarginLeft;
                int             y0     = (iEv <= 9) ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                int             kSum   = 0;

                List <KeyValuePair <double, ASSPoint> > textpath = new List <KeyValuePair <double, ASSPoint> >();
                string outlines = "";
                double lastt0   = -1;
                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    //if (iK > 0) break;
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    string   evStyle         = isJp ? "op_jp" : "op_cn";
                    string   ptStyle         = "op_pt";
                    string   outlineFontname = isJp ? "DFSoGei-W7" : "方正综艺_GBK";
                    int      outlineEncoding = isJp ? 128 : 1;
                    KElement ke     = kelems[iK];
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x     = x0 + this.FontSpace + sz.Width / 2;
                    int        y     = y0 + FontHeight / 2;
                    int        x_an7 = x0;
                    int        y_an7 = y0;
                    StringMask mask  = GetMask(ke.KText, x, y);
                    if (ke.KText.Trim().Length == 0)
                    {
                        sz.Width = 20;
                    }
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    int xOffset = 0;
                    if (!isJp)
                    {
                        xOffset = 1;
                    }
                    else if (iEv == 9 || iEv == 19)
                    {
                        xOffset = 5;
                    }
                    string outlineString = GetOutline(x - FontHeight / 2 + xOffset, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, 156);
                    outlines += " " + outlineString;

                    textpath.Add(new KeyValuePair <double, ASSPoint>(kStart, new ASSPoint {
                        X = x, Y = y, Start = kStart, End = kEnd
                    }));

                    double t0 = ev.Start - 0.5 + iK * 0.1;
                    if (iEv == 9 || iEv == 19)
                    {
                        t0 = ev.Start - 0.5 + iK * 0.04;
                    }
                    double t1 = t0 + 0.5;
                    double t2 = kStart;
                    double t3 = kEnd;
                    double t4 = ev.End - 0.5 + iK * 0.1;
                    double t5 = t4 + 0.5;
                    if (iEv == 9 || iEv == 19)
                    {
                        t4 = ev.End - 0.5 + iK * 0.04;
                    }
                    lastt0 = t0;

                    /*
                     * ass_out.AppendEvent(10, ptStyle, ev.Start, ev.End,
                     *  pos(0, 0) + a(1, "00") + c(1, "0000FF") +
                     *  p(4) + outlineString);
                     * ass_out.AppendEvent(0, evStyle, ev.Start, ev.End,
                     *  pos(x, y) + a(1, "00") +
                     *  ke.KText);
                     * continue;
                     * */

                    string mainColor = Common.scaleColor("C67A82", "C6A87A", (double)iK / (double)(kelems.Count - 1));
                    string shadColor = Common.scaleColor("77333B", "775D33", 1.0 - (double)iK / (double)(kelems.Count - 1));
                    shadColor = Common.scaleColor("000000", shadColor, 0.7);
                    if (iEv <= 9)
                    {
                        shadColor = "FFFFFF";
                    }
                    string backColor = "FFFFFF";

                    string mainColor2 = "4A45AB";
                    string shadColor2 = "353377";
                    if ((isJp && iEv > 4) || (!isJp && iEv - 10 > 4))
                    {
                        string tmp = mainColor;
                        mainColor  = mainColor2;
                        mainColor2 = tmp;
                        tmp        = shadColor;
                        shadColor  = shadColor2;
                        shadColor2 = tmp;
                    }
                    if (iEv > 9)
                    {
                        mainColor2 = mainColor;
                        shadColor2 = shadColor;
                    }

                    if (iEv <= 9)
                    {
                        foreach (Beat bt in GetBeats())
                        {
                            if (bt.Time <= t0 || bt.Time >= t4)
                            {
                                continue;
                            }
                            string btCol = bt.Time <= t2 ? shadColor : shadColor2;
                            if (jEv <= 4)
                            {
                                ass_out.AppendEvent(40, evStyle, bt.Time, bt.Time + 0.4,
                                                    pos(x, y) + fad(0, 0.3) +
                                                    a(3, "00") + c(3, btCol) + ybord(3) + blur(2.5) +
                                                    ke.KText);
                            }
                            else
                            {
                                ass_out.AppendEvent(40, evStyle, bt.Time, bt.Time + 0.4,
                                                    pos(x, y) + fad(0, 0.3) +
                                                    a(3, "00") + c(3, btCol) + xbord(6) + blur(4.5) +
                                                    ke.KText);
                            }
                        }

                        ass_out.AppendEvent(45, evStyle, t0, t2 + 0.5,
                                            pos(x, y) + fad(t1 - t0, 0.5) +
                                            a(1, "00") + c(1, backColor) + a(3, "00") + c(3, shadColor) + bord(1.5) + blur(1.5) +
                                            ke.KText);
                        ass_out.AppendEvent(45, evStyle, t2, t5,
                                            pos(x, y) + fad(0.5, t5 - t4) +
                                            a(1, "00") + c(1, backColor) + a(3, "00") + c(3, shadColor2) + bord(1.5) + blur(1.5) +
                                            ke.KText);
                    }
                    else
                    {
                        ass_out.AppendEvent(45, evStyle, t0, t5,
                                            pos(x, y) + fad(t1 - t0, t5 - t4) +
                                            a(1, "00") + c(1, backColor) + a(3, "00") + c(3, shadColor) + bord(1.5) + blur(1.5) +
                                            ke.KText);
                    }
                    for (int i = 0; i < ((iEv == 9 || iEv == 19) ? 1 : 3); i++)
                    {
                        double rndRange = (iEv == 9 || iEv == 19) ? 8 : (isJp ? 12 : 11);
                        double ptx0     = Common.RandomDouble(rnd, x - rndRange, x + rndRange);
                        double pty0     = Common.RandomDouble(rnd, y - rndRange, y + rndRange);
                        double bordSz   = isJp ? 5 : 4.5;
                        double blurSz   = isJp ? 4.5 : 4.2;
                        if (iEv <= 9)
                        {
                            ass_out.AppendEvent(50, ptStyle, t0, t2 + 0.5,
                                                pos(ptx0, pty0) + fad(t1 - t0, 0.5) + clip(4, outlineString) +
                                                a(1, "44") + a(3, "00") + c(1, mainColor) + c(3, mainColor) + bord(bordSz) + blur(blurSz) +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");
                            ass_out.AppendEvent(50, ptStyle, t2, t5,
                                                pos(ptx0, pty0) + fad(0.5, t5 - t4) + clip(4, outlineString) +
                                                a(1, "44") + a(3, "00") + c(1, mainColor2) + c(3, mainColor2) + bord(bordSz) + blur(blurSz) +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");
                        }
                        else
                        {
                            ass_out.AppendEvent(50, ptStyle, t0, t5,
                                                pos(ptx0, pty0) + fad(t1 - t0, t5 - t4) + clip(4, outlineString) +
                                                a(1, "44") + a(3, "00") + c(1, mainColor) + c(3, mainColor) + bord(bordSz) + blur(blurSz) +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");
                        }
                    }

                    if (iEv > 9)
                    {
                        continue;
                    }

                    ass_out.AppendEvent(70, evStyle, t2, t2 + 0.4,
                                        pos(x, y) + fad(0.00, 0.28) +
                                        a(1, "00") + a(3, "00") + bord(3) + blur(2.8) +
                                        ke.KText);
                }

                if (iEv > 9)
                {
                    continue;
                }

                for (int i = 0; i < textpath.Count - 1; i++)
                {
                    if (textpath[i].Value.End < textpath[i + 1].Value.Start)
                    {
                        textpath[i].Value.End = textpath[i + 1].Value.Start;
                    }
                }
                textpath[textpath.Count - 1].Value.End = ev.End;

                emitterList = new List <ASSPointF>();
                foreach (KeyValuePair <double, ASSPoint> pair in textpath)
                {
                    emitterList.Add(new ASSPointF
                    {
                        Start = pair.Value.Start,
                        End   = pair.Value.End,
                        X     = pair.Value.X + Common.RandomDouble(rnd, -20, 20),
                        Y     = pair.Value.Y + Common.RandomDouble(rnd, -20, 20)
                    });
                }

                forceCurve = new CompositeCurve {
                    MinT = ev.Start, MaxT = ev.End + 10
                };
                double lastag = 0;
                for (double time = forceCurve.MinT; time <= forceCurve.MaxT; time += 0.7)
                {
                    double ag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                    while (Math.Abs(ag - lastag) < Math.PI * 0.5 || Math.Abs(ag - lastag) > Math.PI * 1.5)
                    {
                        ag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                    }
                    lastag = ag;
                    double x = 1000.0 * Math.Cos(ag);
                    double y = 600.0 * Math.Sin(ag);
                    forceCurve.AddCurve(time, time + 0.7, new Line {
                        X0 = x, Y0 = y, X1 = 0, Y1 = 0, Acc = 0.7
                    });
                }

                NumberPerSecond = 20;
                XXParticleSystem xxps = new XXParticleSystem();
                xxps.Emitter                = this;
                xxps.ForceField             = this;
                xxps.StartTime              = ev.Start;
                xxps.EndTime                = ev.End;
                xxps.InterpolationPrecision = 0.03;
                xxps.Resistance             = 0.04;
                xxps.Repulsion              = -4500;
                xxps.Gravity                = 0;
                xxps.GravityPosition        = this;

                xxps.InterpolationPrecision = 0.01;
                List <KeyValuePair <XXParticleElement, List <string> > > result = xxps.RenderT();
                foreach (KeyValuePair <XXParticleElement, List <string> > pair in result)
                {
                    string s     = CreatePolygon(rnd, 9, 9, 4);
                    string ptstr = @"{\p1}m 0 0 l 1 0 1 1 0 1";
                    string ptcol = (iEv <= 4) ? "532BFF" : "FFC0C6";
                    ass_out.AppendEvent(20, "op_pt", pair.Key.Born, pair.Key.Born + pair.Key.Life,
                                        pos(-100, -100) +
                                        pair.Value[1] +
                                        ptstr + "\\N" + r() +
                                        pair.Value[0] +
                                        ptstr + r() +
                                        a(1, "22") + a(3, "77") + blur(2.5) + bord(2) + c(3, ptcol) +
                                        //a(4, "44") + @"{\shad1}" + c(4, "FFFFFF") +
                                        s);
                }

                if (isJp)
                {
                    double ptx0 = textpath[0].Value.X - 50;
                    double ptx1 = textpath.Last().Value.X + 50;
                    double pty0 = textpath[0].Value.Y;
                    double spd  = 400;
                    foreach (Beat bt in GetBeats())
                    {
                        if (iEv == 9)
                        {
                            double ptt0 = bt.Time - 0.15;
                            if (ptt0 < ev.Start || ptt0 >= ev.End - 0.4)
                            {
                                continue;
                            }
                            ass_out.AppendEvent(200, "op_pt", ptt0, ptt0 + (ptx1 - ptx0) / spd,
                                                (iEv % 2 == 0 ? move(ptx1, pty0, ptx0, pty0) : move(ptx0, pty0, ptx1, pty0)) + clip(4, outlines) +
                                                a(1, "00") + blur(3) + frz(-45) + fscx(70) +
                                                p(1) + "m -15 -30 l 15 -30 15 30 -15 30");
                        }
                        else
                        {
                            double ptt0 = lastt0;
                            ass_out.AppendEvent(200, "op_pt", ptt0, ptt0 + (ptx1 - ptx0) / spd,
                                                move(ptx1, pty0, ptx0, pty0) + clip(4, outlines) +
                                                a(1, "00") + blur(3) + frz(-45) + fscx(70) +
                                                p(1) + "m -15 -30 l 15 -30 15 30 -15 30");
                            ass_out.AppendEvent(200, "op_pt", ptt0, ptt0 + (ptx1 - ptx0) / spd,
                                                move(ptx0, pty0, ptx1, pty0) + clip(4, outlines) +
                                                a(1, "00") + blur(3) + frz(-45) + fscx(70) +
                                                p(1) + "m -15 -30 l 15 -30 15 30 -15 30");
                            break;
                        }
                    }
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }