This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpectrumDots.cs
85 lines (73 loc) · 3.13 KB
/
SpectrumDots.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using OpenTK;
using StorybrewCommon.Scripting;
using StorybrewCommon.Storyboarding;
using StorybrewCommon.Animations;
using System;
namespace StorybrewScripts
{
class SpectrumDots : StoryboardObjectGenerator
{
public override void Generate()
{
Spectrum(23115, 44810, true);
Spectrum(153285, 173624, false);
Spectrum(196675, 218370, true);
}
void Spectrum(int StartTime, int EndTime, bool DisplayBottom)
{
var MinimalHeight = 1;
var ScaleY = 70;
float LogScale = 7;
var Position = new Vector2(-103, 257);
var Width = 854f;
int BarCount = 100;
var fftCount = BarCount * 2;
var heightKeyframes = new KeyframedValue<float>[fftCount];
for (var i = 0; i < fftCount; i++) heightKeyframes[i] = new KeyframedValue<float>(null);
var timeStep = Beatmap.GetTimingPointAt(StartTime).BeatDuration / 5;
var offset = timeStep * 0.2;
for (var t = (double)StartTime; t <= EndTime; t += timeStep)
{
var fft = GetFft(t + offset, fftCount, null, OsbEasing.InExpo);
for (var i = 0; i < fftCount; i++)
{
var height = Math.Log10(1 + fft[i] * LogScale) * ScaleY;
if (height < MinimalHeight) height = MinimalHeight;
heightKeyframes[i].Add(t, (float)height);
}
}
var barWidth = Width / BarCount;
for (var i = 0; i < BarCount; i++)
{
var keyframes = heightKeyframes[i];
keyframes.Simplify1dKeyframes(1.5, f => f);
var topBar = GetLayer("").CreateSprite("sb/p.png", OsbOrigin.Centre, new Vector2(Position.X + i * barWidth, 0));
var bottomBar = GetLayer("").CreateSprite("sb/p.png", OsbOrigin.Centre, new Vector2(Position.X + i * barWidth, 0));
topBar.Scale(StartTime, barWidth / 3);
topBar.Fade(StartTime, 0.5);
topBar.Fade(EndTime - 1000, EndTime, 0.5, 0);
topBar.Additive(StartTime);
if (DisplayBottom)
{
bottomBar.Scale(StartTime, barWidth / 3);
bottomBar.Fade(StartTime, 0.5);
bottomBar.Fade(EndTime - 1000, EndTime, 0.5, 0);
bottomBar.Additive(StartTime);
Position.Y = 240;
LogScale = 5.5f;
}
keyframes.ForEachPair((start, end) =>
{
topBar.MoveY(start.Time, end.Time,
(int)(Position.Y - start.Value / 2 * LogScale), (int)(Position.Y - end.Value / 2 * LogScale));
if (DisplayBottom)
{
bottomBar.MoveY(start.Time, end.Time,
(int)(Position.Y + start.Value / 2 * LogScale), (int)(Position.Y + end.Value / 2 * LogScale));
}
},
MinimalHeight, s => s);
}
}
}
}