public override void Update(float frameTime)
        {
            Hue += frameTime / 10;
            if (Hue > 1)
            {
                Hue -= 1;
            }

            LightComponent.Color = Color4.FromHsl(new Vector4(Hue, 1, 0.5f, 0.5f));
        }
 private Color4 getColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, 1));
 private Color4 getColour(float saturation, float lightness) => Color4.FromHsl(new Vector4(colourHue / 360, saturation, lightness, 1));
Exemple #4
0
 public Color4 ForOverlayElement(OverlayColourScheme colourScheme, float saturation, float lightness, float opacity = 1) => Color4.FromHsl(new Vector4(getBaseHue(colourScheme), saturation, lightness, opacity));
Exemple #5
0
        public override void Generate()
        {
            if (StartTime == EndTime)
            {
                StartTime = (int)Beatmap.HitObjects.First().StartTime;
                EndTime   = (int)Beatmap.HitObjects.Last().EndTime;
            }
            EndTime   = Math.Min(EndTime, (int)AudioDuration);
            StartTime = Math.Min(StartTime, EndTime);

            var bitmap = GetMapsetBitmap(Path);

            var duration  = (double)(EndTime - StartTime);
            var loopCount = (int)Math.Floor(duration / Lifetime);

            var layer = GetLayer("");

            for (var i = 0; i < ParticleCount; i++)
            {
                var spawnAngle    = Random(Math.PI * 2);
                var spawnDistance = (float)(SpawnSpread * Math.Sqrt(Random(1f)));

                var moveAngle    = MathHelper.DegreesToRadians(Angle + Random(-AngleSpread, AngleSpread) * 0.5f);
                var moveDistance = Speed * Lifetime * 0.001f;

                var spriteRotation = moveAngle + MathHelper.DegreesToRadians(Rotation);

                if (Rotation == 0)
                {
                    spriteRotation = 0;
                }

                var startPosition = SpawnOrigin + new Vector2((float)Math.Cos(spawnAngle), (float)Math.Sin(spawnAngle)) * spawnDistance;
                var endPosition   = startPosition + new Vector2((float)Math.Cos(moveAngle), (float)Math.Sin(moveAngle)) * moveDistance;

                var loopDuration = duration / loopCount;
                var startTime    = StartTime + (i * loopDuration) / ParticleCount;
                var endTime      = startTime + loopDuration * loopCount;

                if (!isVisible(bitmap, startPosition, endPosition, (float)spriteRotation, (float)loopDuration))
                {
                    continue;
                }

                var color = Color;
                if (ColorVariance > 0)
                {
                    ColorVariance = MathHelper.Clamp(ColorVariance, 0, 1);

                    var hsba = Color4.ToHsl(color);
                    var sMin = Math.Max(0, hsba.Y - ColorVariance * 0.5f);
                    var sMax = Math.Min(sMin + ColorVariance, 1);
                    var vMin = Math.Max(0, hsba.Z - ColorVariance * 0.5f);
                    var vMax = Math.Min(vMin + ColorVariance, 1);

                    color = Color4.FromHsl(new Vector4(
                                               hsba.X,
                                               (float)Random(sMin, sMax),
                                               (float)Random(vMin, vMax),
                                               hsba.W));
                }

                var particle = layer.CreateSprite(Path, Origin);
                if (spriteRotation != 0)
                {
                    particle.Rotate(startTime, spriteRotation);
                }
                if (color.R != 1 || color.G != 1 || color.B != 1)
                {
                    particle.Color(startTime, color);
                }
                if (Scale.X != 1 || Scale.Y != 1)
                {
                    if (Scale.X != Scale.Y)
                    {
                        particle.ScaleVec(startTime, Scale.X, Scale.Y);
                    }
                    else
                    {
                        particle.Scale(startTime, Scale.X);
                    }
                }
                if (Additive)
                {
                    particle.Additive(startTime, endTime);
                }

                particle.StartLoopGroup(startTime, loopCount);
                particle.Fade(OsbEasing.Out, 0, loopDuration * 0.2, 0, color.A);
                particle.Fade(OsbEasing.In, loopDuration * 0.8, loopDuration, color.A, 0);
                particle.Move(Easing, 0, loopDuration, startPosition, endPosition);
                particle.EndGroup();
            }
        }
Exemple #6
0
 public static Color FromHsl(Vector4 vec)
 {
     return(Color4.FromHsl(vec));
 }
 private Color4 getColour(LyricEditorMode mode, float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(mode), saturation, lightness, 1));
Exemple #8
0
        public override void Generate()
        {
            var layer = GetLayer("PostKiaiParticles");

            var color         = Color;
            var ColorVariance = MathHelper.Clamp(0.6, 0, 1);
            var hsba          = Color4.ToHsl(color);
            var sMin          = Math.Max(0, hsba.Y - ColorVariance * 0.5f);
            var sMax          = Math.Min(sMin + ColorVariance, 1);
            var vMin          = Math.Max(0, hsba.Z - ColorVariance * 0.5f);
            var vMax          = Math.Min(vMin + ColorVariance, 1);

            for (double x = StartTime; x < StartTime + tick(0, (double)1 / (double)16); x += tick(0, 1))
            {
                Vector2 initPos1 = new Vector2(Random(-70, 130), -10);
                Vector2 initPos2 = new Vector2(Random(490, 690), -10);

                var heart1 = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);
                var heart2 = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);

                color = Color4.FromHsl(new Vector4(
                                           hsba.X,
                                           (float)Random(sMin, sMax),
                                           (float)Random(vMin, vMax),
                                           hsba.W));

                heart1.Color(x, color);
                heart2.Color(x, color);

                heart1.Fade((OsbEasing)9, x + tick(0, 1), x + tick(0, (double)1 / (double)8), 1, 0);
                heart2.Fade((OsbEasing)9, x + tick(0, 1), x + tick(0, (double)1 / (double)8), 1, 0);

                heart1.Scale(x, Random(0.7, 0.9));
                heart2.Scale(x, Random(0.7, 0.9));

                heart1.Rotate(x, x + tick(0, (double)1 / (double)8), MathHelper.DegreesToRadians(Random(-100, 100)), MathHelper.DegreesToRadians(Random(-100, 100)));
                heart2.Rotate(x, x + tick(0, (double)1 / (double)8), MathHelper.DegreesToRadians(Random(-100, 100)), MathHelper.DegreesToRadians(Random(-100, 100)));

                heart1.Move(x, x + tick(0, (double)1 / (double)8), initPos1, initPos1 + new Vector2(Random(-100, 100), Random(400, 500)));
                heart2.Move(x, x + tick(0, (double)1 / (double)8), initPos2, initPos2 + new Vector2(Random(-100, 100), Random(400, 500)));
            }

            for (double x = StartTime + tick(0, (double)1 / (double)16); x < StartTime + tick(0, (double)1 / (double)32); x += tick(0, 4))
            {
                Vector2 initPos1 = new Vector2(Random(-70, 130), -10);
                Vector2 initPos2 = new Vector2(Random(490, 690), -10);

                var heart1 = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);
                var heart2 = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);

                color = Color4.FromHsl(new Vector4(
                                           hsba.X,
                                           (float)Random(sMin, sMax),
                                           (float)Random(vMin, vMax),
                                           hsba.W));

                heart1.Color(x, color);
                heart2.Color(x, color);

                heart1.Fade((OsbEasing)9, x + tick(0, 1), x + tick(0, (double)1 / (double)4), 1, 0);
                heart2.Fade((OsbEasing)9, x + tick(0, 1), x + tick(0, (double)1 / (double)4), 1, 0);

                heart1.Scale(x, Random(0.7, 0.9));
                heart2.Scale(x, Random(0.7, 0.9));

                heart1.Rotate(x, x + tick(0, (double)1 / (double)4), MathHelper.DegreesToRadians(Random(-100, 100)), MathHelper.DegreesToRadians(Random(-100, 100)));
                heart2.Rotate(x, x + tick(0, (double)1 / (double)4), MathHelper.DegreesToRadians(Random(-100, 100)), MathHelper.DegreesToRadians(Random(-100, 100)));

                heart1.Move(x, x + tick(0, (double)1 / (double)4), initPos1, initPos1 + new Vector2(Random(-100, 100), Random(400, 500)));
                heart2.Move(x, x + tick(0, (double)1 / (double)4), initPos2, initPos2 + new Vector2(Random(-100, 100), Random(400, 500)));
            }

            for (double x = StartTime + tick(0, (double)1 / (double)32); x < StartTime + tick(0, (double)1 / (double)48); x += tick(0, 8))
            {
                Vector2 initPos1 = new Vector2(Random(-70, 130), -10);
                Vector2 initPos2 = new Vector2(Random(490, 690), -10);

                var heart1 = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);
                var heart2 = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);

                color = Color4.FromHsl(new Vector4(
                                           hsba.X,
                                           (float)Random(sMin, sMax),
                                           (float)Random(vMin, vMax),
                                           hsba.W));

                heart1.Color(x, color);
                heart2.Color(x, color);

                heart1.Fade((OsbEasing)9, x + tick(0, 1), x + tick(0, (double)1 / (double)2), 1, 0);
                heart2.Fade((OsbEasing)9, x + tick(0, 1), x + tick(0, (double)1 / (double)2), 1, 0);

                heart1.Scale(x, Random(0.7, 0.9));
                heart2.Scale(x, Random(0.7, 0.9));

                heart1.Rotate(x, x + tick(0, (double)1 / (double)2), MathHelper.DegreesToRadians(Random(-100, 100)), MathHelper.DegreesToRadians(Random(-100, 100)));
                heart2.Rotate(x, x + tick(0, (double)1 / (double)2), MathHelper.DegreesToRadians(Random(-100, 100)), MathHelper.DegreesToRadians(Random(-100, 100)));

                heart1.Move(x, x + tick(0, (double)1 / (double)2), initPos1, initPos1 + new Vector2(Random(-100, 100), Random(400, 500)));
                heart2.Move(x, x + tick(0, (double)1 / (double)2), initPos2, initPos2 + new Vector2(Random(-100, 100), Random(400, 500)));
            }
            int           run         = 0;
            List <double> curveCircle = CalculateCurve(315, 240, 520.0);
            Vector2       initPos     = new Vector2(315, 240);

            for (double x = StartTime + tick(0, (double)1 / (double)48); x < StartTime + tick(0, (double)1 / (double)51); x += tick(0, 4))
            {
                for (int y = 1; y <= 4; y += 1)
                {
                    color = Color4.FromHsl(new Vector4(
                                               hsba.X,
                                               (float)Random(sMin, sMax),
                                               (float)Random(vMin, vMax),
                                               hsba.W));

                    var heart = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);
                    heart.Color(x, color);
                    Vector2 endPos = new Vector2((float)curveCircle[(run + 90 * y) % 360], (float)curveCircle[(run + 1 + 90 * y) % 360]);
                    heart.Move(x, x + tick(0, 0.75), initPos, endPos);
                    run += 2;
                }
            }
            run = 0;
            for (double x = StartTime + tick(0, (double)1 / (double)48); x < StartTime + tick(0, (double)1 / (double)51); x += tick(0, 4))
            {
                for (int y = 1; y <= 4; y += 1)
                {
                    color = Color4.FromHsl(new Vector4(
                                               (float)Random(sMin, sMax),
                                               (float)Random(vMin, vMax),
                                               hsba.W,
                                               hsba.X));

                    var heart = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);
                    heart.Color(x, color);
                    Vector2 endPos = new Vector2((float)curveCircle[(run + 90 * y) % 360], (float)curveCircle[(run + 1 + 90 * y) % 360]);
                    heart.Move(StartTime + tick(0, (double)1 / (double)51) + run * 2, StartTime + tick(0, (double)1 / (double)52), endPos, initPos);
                    run += 2;
                }
            }
            run = 360;
            for (double x = StartTime + tick(0, (double)1 / (double)52); x < StartTime + tick(0, (double)1 / (double)55); x += tick(0, 4))
            {
                for (int y = 1; y <= 4; y += 1)
                {
                    color = Color4.FromHsl(new Vector4(
                                               hsba.X,
                                               (float)Random(sMin, sMax),
                                               (float)Random(vMin, vMax),
                                               hsba.W));

                    var heart = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);
                    heart.Color(x, color);
                    Vector2 endPos = new Vector2((float)curveCircle[(run + 90 * y) % 360], (float)curveCircle[(run + 1 + 90 * y) % 360]);
                    heart.Move((OsbEasing)4, x, x + tick(0, 0.75), initPos, endPos);
                    run -= 2;
                }
            }
        }
        public override void Generate()
        {
            var layer    = GetLayer("GayPart");
            var BGbitmap = GetMapsetBitmap(PinkBG);

            var backgroundPink = layer.CreateSprite(PinkBG, OsbOrigin.Centre);

            backgroundPink.Scale(StartTime, 570.0f / BGbitmap.Height);
            backgroundPink.Fade(EndTime, EndTime + tick(0, (double)1 / (double)2), 1, 0.5);

            var background = layer.CreateSprite(BG, OsbOrigin.Centre);

            background.Scale(StartTime, 570.0f / BGbitmap.Height);
            double lastrng = 0.0;

            for (int x = StartTime; x <= EndTime; x += (int)tick(0, 1.2))
            {
                double rng = Random(0, 0.35);
                background.Fade(x, x + tick(0, 1), lastrng, rng);
                lastrng = rng;
            }

            var flash = layer.CreateSprite(Flash, OsbOrigin.Centre);

            flash.Scale(StartTime, 480.0f / BGbitmap.Height);
            flash.Fade(StartTime, StartTime + tick(0, (double)1 / (double)8), 0.5, 0);

            flash.Fade(EndTime, EndTime + tick(0, (double)1 / (double)2), 0, 0.5);

            for (int x = -107; x <= 780; x += 40)
            {
                for (int y = 0; y <= 500; y += 40)
                {
                    var pixel = layer.CreateSprite(Pixel, OsbOrigin.Centre, new Vector2(x, y));
                    pixel.Fade(StartTime, 0.5);
                    pixel.Scale((OsbEasing)8, StartTime, StartTime + tick(0, (double)1 / (double)8), 20, 0);
                    pixel.Rotate((OsbEasing)8, StartTime, StartTime + tick(0, (double)1 / (double)8), MathHelper.DegreesToRadians(0), MathHelper.DegreesToRadians(90));
                    pixel.Fade(StartTime, StartTime + tick(0, (double)1 / (double)8), 1, 0.4);
                }
            }

            var color         = Color;
            var ColorVariance = MathHelper.Clamp(0.6, 0, 1);
            var hsba          = Color4.ToHsl(color);
            var sMin          = Math.Max(0, hsba.Y - ColorVariance * 0.5f);
            var sMax          = Math.Min(sMin + ColorVariance, 1);
            var vMin          = Math.Max(0, hsba.Z - ColorVariance * 0.5f);
            var vMax          = Math.Min(vMin + ColorVariance, 1);

            for (double x = StartTime; x < EndTime; x += tick(0, 2))
            {
                Vector2 Pos1 = new Vector2(Random(-100, 720), 490);
                Vector2 Pos2 = new Vector2(Pos1.X + Random(-100, 100), -50);

                var heart1 = layer.CreateSprite(HeartParticle, OsbOrigin.Centre);

                color = Color4.FromHsl(new Vector4(
                                           hsba.X,
                                           (float)Random(sMin, sMax),
                                           (float)Random(vMin, vMax),
                                           hsba.W));

                heart1.Color(x, color);
                heart1.Fade((OsbEasing)9, x + tick(0, 1), EndTime, 1, 0);
                heart1.Scale(x, Random(0.7, 2));
                heart1.Rotate(x, x + tick(0, (double)1 / (double)8), MathHelper.DegreesToRadians(Random(-100, 100)), MathHelper.DegreesToRadians(Random(-100, 100)));
                heart1.Move(x, x + tick(0, (double)1 / (double)8), Pos1, Pos2);
            }
            var droptime    = EndTime;
            var LineEndTime = droptime + tick(0, (double)1 / (double)2);

            for (int x = 0; x <= 3; x++)
            {
                var pixel = layer.CreateSprite(Pixel, OsbOrigin.Centre, new Vector2(220 * x, 240));
                pixel.ScaleVec(droptime, droptime + tick(0, 2), 0, 854 / 2, 110, 854 / 2);
                pixel.Fade(droptime, droptime + tick(0, 2), 1, 0.5);
                pixel.Fade(droptime + tick(0, 2), LineEndTime, 0.5, 1);
                droptime += (int)tick(0, 2);
            }
        }
Exemple #10
0
        public void generatePerCharacter(FontGenerator font, SubtitleSet subtitles, StoryboardLayer layer, bool additive)
        {
            var squaresLayer = GetLayer("lyricsSquares");

            foreach (var subtitleLine in subtitles.Lines)
            {
                var letterY    = SubtitleY;
                var i          = 0;
                var lineOffset = 0;
                foreach (var line in subtitleLine.Text.Split('\n'))
                {
                    var lineWidth  = 0f;
                    var lineHeight = 0f;
                    foreach (var letter in line)
                    {
                        var texture = font.GetTexture(letter.ToString());
                        lineWidth += texture.BaseWidth * FontScale;
                        lineHeight = Math.Max(lineHeight, texture.BaseHeight * FontScale);
                    }

                    var letterX = 320 - lineWidth * 0.5f + lineOffset;
                    foreach (var letter in line)
                    {
                        var texture = font.GetTexture(letter.ToString());
                        if (!texture.IsEmpty)
                        {
                            var initialPosition = new Vector2(letterX + 40, letterY) + texture.OffsetFor(Origin) * FontScale;

                            var position = new Vector2(letterX, letterY)
                                           + texture.OffsetFor(Origin) * FontScale;

                            var finalPosition = new Vector2(letterX + Random(-15, 15), letterY + Random(-15, 15)) + texture.OffsetFor(Origin) * FontScale;

                            if (squares)
                            {
                                for (int f = 0; f < 3; f++)
                                {
                                    var color = Color;
                                    if (ColorVariance > 0)
                                    {
                                        ColorVariance = MathHelper.Clamp(ColorVariance, 0, 1);

                                        var hsba = Color4.ToHsl(color);
                                        var sMin = Math.Max(0, hsba.Y - ColorVariance * 0.5f);
                                        var sMax = Math.Min(sMin + ColorVariance, 1);
                                        var vMin = Math.Max(0, hsba.Z - ColorVariance * 0.5f);
                                        var vMax = Math.Min(vMin + ColorVariance, 1);

                                        color = Color4.FromHsl(new Vector4(
                                                                   hsba.X,
                                                                   (float)Random(sMin, sMax),
                                                                   (float)Random(vMin, vMax),
                                                                   hsba.W));
                                    }


                                    var initiialRotation = Random(0, MathHelper.DegreesToRadians(360));
                                    var endRotation      = Random(0, MathHelper.DegreesToRadians(360));

                                    var sqaureIinitPos = new Vector2(letterX + Random(-30, 30), letterY + Random(-30, 30)) + texture.OffsetFor(Origin) * FontScale;

                                    var squarePosition = new Vector2(letterX + Random(-15, 15), letterY + Random(-15, 15)) + texture.OffsetFor(Origin) * FontScale;

                                    var square = squaresLayer.CreateSprite("sb/etc/p.png", Origin, squarePosition);
                                    square.Move(subtitleLine.StartTime - 400 + i, subtitleLine.StartTime + i, sqaureIinitPos, squarePosition);
                                    square.Scale(subtitleLine.StartTime - 400 + i, subtitleLine.EndTime, 20, 20);
                                    square.Additive(subtitleLine.StartTime - 400 + i, subtitleLine.EndTime);
                                    square.Fade(subtitleLine.StartTime - 400 + i, subtitleLine.StartTime + i, 0, 0.1);
                                    square.Rotate(subtitleLine.StartTime - 400 + i, subtitleLine.EndTime, initiialRotation, endRotation);
                                    square.Color(subtitleLine.StartTime - 400 + i, color);
                                    square.Fade(subtitleLine.EndTime - 400, subtitleLine.EndTime, 0.1, 0);
                                }
                            }

                            var sprite = layer.CreateSprite(texture.Path, Origin, position);
                            sprite.Move(OsbEasing.Out, subtitleLine.StartTime - 400 + i, subtitleLine.StartTime + i, initialPosition, position);
                            // sprite.Scale(subtitleLine.StartTime - 200 + i, subtitleLine.StartTime + i, 0, FontScale);
                            // sprite.Rotate(OsbEasing.Out, subtitleLine.StartTime - 400 + i, subtitleLine.StartTime + i, MathHelper.DegreesToRadians(Random(0, 360)), MathHelper.DegreesToRadians(0));
                            sprite.Fade(OsbEasing.Out, subtitleLine.StartTime - 400 + i, subtitleLine.StartTime + i, 0, 1);
                            // sprite.MoveY(subtitleLine.StartTime - 200 + i, subtitleLine.StartTime + i, letterY - 15, letterY);
                            sprite.Fade(OsbEasing.In, subtitleLine.EndTime - 400, subtitleLine.EndTime, 1, 0);
                            sprite.Scale(OsbEasing.In, subtitleLine.EndTime - 400, subtitleLine.EndTime, FontScale, 0);
                            sprite.Move(OsbEasing.In, subtitleLine.EndTime - 400, subtitleLine.EndTime, position, finalPosition);

                            if (additive)
                            {
                                sprite.Additive(subtitleLine.StartTime - 400, subtitleLine.EndTime);
                            }
                            i += 65;
                        }
                        letterX += texture.BaseWidth * FontScale;
                    }
                    // lineOffset += 120;
                    letterY += lineHeight;
                }
            }
        }
 private Color4 getColour(SettingsSection section, float saturation, float lightness) => Color4.FromHsl(new Vector4(getBaseHue(section), saturation, lightness, 1));
Exemple #12
0
        public override void Generate()
        {
            var ModelLayer = GetLayer("ModelLayer");
            var ModelArray = readModel(FilePath);

            for (int i = 0; i < ModelArray.Length; i++)
            {  //Translated from Exile-'s work.
                var X          = ModelArray[i].X;
                var Y          = ModelArray[i].Y;
                var Z          = ModelArray[i].Z;
                var Angle      = Math.Atan2(Z, X);
                var Delay      = spinDuration * (Angle / (Math.PI * 2));
                var Radius     = meshScale * Math.Sqrt((X * X) + (Z * Z));
                var ModelPixel = ModelLayer.CreateSprite(SpritePath, OsbOrigin.Centre, new Vector2(320, 240));
                if (spin)
                {
                    ModelPixel.StartLoopGroup(startTime - Delay - spinDuration, (EndTime - startTime) / spinDuration + 3);
                    for (int I = 0; I < 4; I++)
                    {
                        double startAngle    = Math.PI * I / 2;
                        double endAngle      = Math.PI * (I + 1) / 2;
                        double startTimeSpin = spinDuration * I / 4;
                        double endTimeSpin   = spinDuration * (I + 1) / 4;
                        ModelPixel.MoveX((OsbEasing)(I % 2 + 1), startTimeSpin, endTimeSpin, centerX + Radius * Math.Sin(startAngle), centerX + Radius * Math.Sin(endAngle));
                        ModelPixel.MoveY((OsbEasing)((I + 1) % 2 + 1), startTimeSpin, endTimeSpin, centerY - Y * meshScale + tilt * Radius * Math.Cos(startAngle), centerY - Y * meshScale + tilt * Radius * Math.Cos(endAngle));
                    }
                    ModelPixel.EndGroup();
                    ModelPixel.StartLoopGroup(startTime, 110);
                    ModelPixel.Scale(0, 1.2);
                    ModelPixel.Scale(0, Beatmap.GetTimingPointAt(startTime).BeatDuration, 0.8, 0.45);
                    ModelPixel.EndGroup();
                }
                else
                {
                    double x = centerX + Radius * Math.Sin(Angle);
                    double y = centerY + tilt * Radius * Math.Cos(Angle) - Y * meshScale;
                    ModelPixel.Move(OsbEasing.None, startTime, startTime, x, y, x, y);
                }
                ModelPixel.Fade(startTime - 1000, 0);
                ModelPixel.Fade(startTime, 1);
                ModelPixel.Fade(startTime, 1);
                ModelPixel.Fade(EndTime, 0);

                var color = Color;
                if (ColorVariance > 0)
                {
                    ColorVariance = MathHelper.Clamp(ColorVariance, 0, 1);

                    var hsba = Color4.ToHsl(color);
                    var sMin = Math.Max(0, hsba.Y - ColorVariance * 0.5f);
                    var sMax = Math.Min(sMin + ColorVariance, 1);
                    var vMin = Math.Max(0, hsba.Z - ColorVariance * 0.5f);
                    var vMax = Math.Min(vMin + ColorVariance, 1);

                    color = Color4.FromHsl(new Vector4(
                                               hsba.X,
                                               (float)Random(sMin, sMax),
                                               (float)Random(vMin, vMax),
                                               hsba.W));
                }

                ModelPixel.Color(startTime, color);

                ModelPixel.Scale(startTime, SpriteSize);
            }
            Log($"Mesh - {(DateTime.Now - Process.GetCurrentProcess().StartTime).TotalSeconds}");
        }
Exemple #13
0
        public override void Generate()
        {
            if (StartTime == EndTime)
            {
                StartTime = (int)Beatmap.HitObjects.First().StartTime;
                EndTime   = (int)Beatmap.HitObjects.Last().EndTime;
            }
            EndTime   = Math.Min(EndTime, (int)AudioDuration);
            StartTime = Math.Min(StartTime, EndTime);

            var bitmap = GetMapsetBitmap(SpritePath);

            var heightKeyframes = new KeyframedValue <float> [BarCount];

            for (var i = 0; i < BarCount; i++)
            {
                heightKeyframes[i] = new KeyframedValue <float>(null);
            }

            var fftTimeStep = Beatmap.GetTimingPointAt(StartTime).BeatDuration / BeatDivisor;
            var fftOffset   = fftTimeStep * 0.2;

            for (var time = (double)StartTime; time < EndTime; time += fftTimeStep)
            {
                var fft = GetFft(time + fftOffset, BarCount, null, FftEasing);
                for (var i = 0; i < BarCount; i++)
                {
                    var height = (float)Math.Log10(1 + fft[i] * LogScale) * Scale.Y / bitmap.Height;
                    if (height < MinimalHeight)
                    {
                        height = MinimalHeight;
                    }

                    heightKeyframes[i].Add(time, height);
                }
            }

            var layer    = GetLayer("Spectrum");
            var barWidth = Width / BarCount;

            for (var i = 0; i < BarCount; i++)
            {
                var keyframes = heightKeyframes[i];
                keyframes.Simplify1dKeyframes(Tolerance, h => h);

                var bar = layer.CreateSprite(SpritePath, SpriteOrigin, new Vector2(Position.X + i * barWidth, Position.Y));
                bar.CommandSplitThreshold = 300;

                var color = Color;
                if (ColorVariance > 0)
                {
                    ColorVariance = MathHelper.Clamp(ColorVariance, 0, 1);

                    var hsba = Color4.ToHsl(color);
                    var sMin = Math.Max(0, hsba.Y - ColorVariance * 0.5f);
                    var sMax = Math.Min(sMin + ColorVariance, 1);
                    var vMin = Math.Max(0, hsba.Z - ColorVariance * 0.5f);
                    var vMax = Math.Min(vMin + ColorVariance, 1);

                    color = Color4.FromHsl(new Vector4(
                                               hsba.X,
                                               (float)Random(sMin, sMax),
                                               (float)Random(vMin, vMax),
                                               hsba.W));
                }

                bar.Color(StartTime, color);
                bar.Additive(StartTime, EndTime);

                var scaleX = Scale.X * barWidth / bitmap.Width;
                scaleX = (float)Math.Floor(scaleX * 10) / 10.0f;

                var hasScale = false;
                keyframes.ForEachPair(
                    (start, end) =>
                {
                    hasScale = true;
                    bar.ScaleVec(start.Time, end.Time,
                                 scaleX, start.Value,
                                 scaleX, end.Value);
                },
                    MinimalHeight,
                    s => (float)Math.Round(s, CommandDecimals)
                    );
                if (!hasScale)
                {
                    bar.ScaleVec(StartTime, scaleX, MinimalHeight);
                }
            }
        }