Skip to content

Commit

Permalink
add - Added new screensaver: PointTrack
Browse files Browse the repository at this point in the history
---

We've added a new screensaver: PointTrack

---

Type: add
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Jan 2, 2025
1 parent 302a2c2 commit fb44a03
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7324,5 +7324,100 @@
]
}
]
},
{
"Name": "PointTrack",
"Desc": "Block moving in a wave pattern with green rulers tracking its position.",
"Keys": [
{
"Name": "Delay in Milliseconds",
"Type": "SInt",
"Variable": "PointTrackDelay",
"Description": "How many milliseconds to wait before making the next write?"
},
{
"Name": "Horizontal Frequency Level",
"Type": "SDouble",
"Variable": "PointTrackHorizontalFrequencyLevel",
"Description": "The level of the horizontal frequency. This is the denominator of the Pi value in mathematics. Use this to create beautiful wavy swivels!"
},
{
"Name": "Vertical Frequency Level",
"Type": "SDouble",
"Variable": "PointTrackVerticalFrequencyLevel",
"Description": "The level of the vertical frequency. This is the denominator of the Pi value in mathematics. Use this to create beautiful wavy swivels!"
},
{
"Name": "Color settings",
"Type": "SMultivar",
"Description": "This allows you to configure the colors",
"Variables": [
{
"Name": "Minimum red color level",
"Type": "SIntSlider",
"Variable": "PointTrackMinimumRedColorLevel",
"Description": "Minimum red color level. The minimum accepted value is 0 and the maximum accepted value is 255.",
"MinimumValue": 0,
"MaximumValue": 255
},
{
"Name": "Minimum green color level",
"Type": "SIntSlider",
"Variable": "PointTrackMinimumGreenColorLevel",
"Description": "Minimum green color level. The minimum accepted value is 0 and the maximum accepted value is 255.",
"MinimumValue": 0,
"MaximumValue": 255
},
{
"Name": "Minimum blue color level",
"Type": "SIntSlider",
"Variable": "PointTrackMinimumBlueColorLevel",
"Description": "Minimum blue color level. The minimum accepted value is 0 and the maximum accepted value is 255.",
"MinimumValue": 0,
"MaximumValue": 255
},
{
"Name": "Minimum color level",
"Type": "SIntSlider",
"Variable": "PointTrackMinimumColorLevel",
"Description": "Minimum color level. The minimum accepted value is 0 and the maximum accepted value is 255 for 255 colors or 16 for 16 colors.",
"MinimumValue": 0,
"MaximumValue": 255
},
{
"Name": "Maximum red color level",
"Type": "SIntSlider",
"Variable": "PointTrackMaximumRedColorLevel",
"Description": "Maximum red color level. The minimum accepted value is 0 and the maximum accepted value is 255.",
"MinimumValue": 0,
"MaximumValue": 255
},
{
"Name": "Maximum green color level",
"Type": "SIntSlider",
"Variable": "PointTrackMaximumGreenColorLevel",
"Description": "Maximum green color level. The minimum accepted value is 0 and the maximum accepted value is 255.",
"MinimumValue": 0,
"MaximumValue": 255
},
{
"Name": "Maximum blue color level",
"Type": "SIntSlider",
"Variable": "PointTrackMaximumBlueColorLevel",
"Description": "Maximum blue color level. The minimum accepted value is 0 and the maximum accepted value is 255.",
"MinimumValue": 0,
"MaximumValue": 255
},
{
"Name": "Maximum color level",
"Type": "SIntSlider",
"Variable": "PointTrackMaximumColorLevel",
"Description": "Maximum color level. The minimum accepted value is 0 and the maximum accepted value is 255 for 255 colors or 16 for 16 colors.",
"MinimumValue": 0,
"MaximumValue": 255
}
]
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ internal class ScreensaverPackInit : IAddon
{ "numberscatter", new NumberScatterDisplay() },
{ "omen", new OmenDisplay() },
{ "particles", new ParticlesDisplay() },
{ "pointtrack", new PointTrackDisplay() },
{ "progressclock", new ProgressClockDisplay() },
{ "pulse", new PulseDisplay() },
{ "ramp", new RampDisplay() },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
//
// Nitrocid KS Copyright (C) 2018-2025 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

using System;
using System.Collections.Generic;
using System.Linq;
using Terminaux.Writer.ConsoleWriters;
using Nitrocid.Drivers.RNG;
using Nitrocid.Kernel.Debugging;
using Nitrocid.Misc.Screensaver;
using Nitrocid.Kernel.Configuration;
using Terminaux.Colors;
using Terminaux.Base;
using Terminaux.Colors.Data;
using System.Text;
using Terminaux.Writer.CyclicWriters;

namespace Nitrocid.ScreensaverPacks.Screensavers
{
/// <summary>
/// Display for PointTrack
/// </summary>
public class PointTrackDisplay : BaseScreensaver, IScreensaver
{
private Color targetColor = ConsoleColors.Lime;
private int posIdxVertical = 0;
private int posIdxHorizontal = 0;

/// <inheritdoc/>
public override string ScreensaverName =>
"PointTrack";

/// <inheritdoc/>
public override void ScreensaverPreparation()
{
posIdxVertical = 0;
posIdxHorizontal = 0;

// Make an initial color storage
int RedColorNum = RandomDriver.Random(ScreensaverPackInit.SaversConfig.TrailsMinimumRedColorLevel, ScreensaverPackInit.SaversConfig.TrailsMaximumRedColorLevel);
int GreenColorNum = RandomDriver.Random(ScreensaverPackInit.SaversConfig.TrailsMinimumGreenColorLevel, ScreensaverPackInit.SaversConfig.TrailsMaximumGreenColorLevel);
int BlueColorNum = RandomDriver.Random(ScreensaverPackInit.SaversConfig.TrailsMinimumBlueColorLevel, ScreensaverPackInit.SaversConfig.TrailsMaximumBlueColorLevel);
targetColor = new(RedColorNum, GreenColorNum, BlueColorNum);
DebugWriter.WriteDebugConditional(Config.MainConfig.ScreensaverDebug, DebugLevel.I, "Got color (R;G;B: {0};{1};{2})", RedColorNum, GreenColorNum, BlueColorNum);
}

/// <inheritdoc/>
public override void ScreensaverLogic()
{
ConsoleWrapper.CursorVisible = false;
ColorTools.LoadBack();

// First, prepare how many dots to render according to the console size
int Height = ConsoleWrapper.WindowHeight - 4;
int Width = ConsoleWrapper.WindowWidth - 4;

// Then, go ahead and make these bars swivel themselves.
List<int> CurrentPosVertical = [];
List<int> CurrentPosHorizontal = [];
double FrequencyVertical = Math.PI / ScreensaverPackInit.SaversConfig.PointTrackVerticalFrequencyLevel;
double FrequencyHorizontal = Math.PI / ScreensaverPackInit.SaversConfig.PointTrackHorizontalFrequencyLevel;

// Set the current vertical positions
double TimeSecsVertical = 0.0;
bool isSetVertical = false;
while (true)
{
TimeSecsVertical += 0.1;
double calculatedHeight = Height * Math.Cos(FrequencyVertical * TimeSecsVertical) / 2;
CurrentPosVertical.Add((int)calculatedHeight);
if ((int)calculatedHeight == Height / 2 && isSetVertical)
break;
if (!isSetVertical && (int)calculatedHeight < Height / 2)
isSetVertical = true;
}

// Set the current horizontal positions
double TimeSecsHorizontal = 0.0;
bool isSetHorizontal = false;
while (true)
{
TimeSecsHorizontal += 0.1;
double calculatedWidth = Width * Math.Cos(FrequencyHorizontal * TimeSecsHorizontal) / 2;
CurrentPosHorizontal.Add((int)calculatedWidth);
if ((int)calculatedWidth == Width / 2 && isSetHorizontal)
break;
if (!isSetHorizontal && (int)calculatedWidth < Width / 2)
isSetHorizontal = true;
}

// Render the block and the position rulers
posIdxVertical++;
if (posIdxVertical >= CurrentPosVertical.Count)
posIdxVertical = 0;
posIdxHorizontal++;
if (posIdxHorizontal >= CurrentPosHorizontal.Count)
posIdxHorizontal = 0;
int PosVertical = CurrentPosVertical[posIdxVertical] + Math.Abs(CurrentPosVertical.Min()) + 2;
int PosHorizontal = CurrentPosHorizontal[posIdxHorizontal] + Math.Abs(CurrentPosHorizontal.Min()) + 2;
if (!ConsoleResizeHandler.WasResized(false))
{
// Render the block
TextWriterWhereColor.WriteWhereColorBack(" ", PosHorizontal, PosVertical, Color.Empty, targetColor);

// Now, make the position ruler writers
var lineBuilder = new StringBuilder();
var topRuler = new Line()
{
DoubleWidth = false,
StartPos = new(PosHorizontal, 0),
EndPos = new(PosHorizontal, PosVertical - 4),
Color = ConsoleColors.Lime,
};
var bottomRuler = new Line()
{
DoubleWidth = false,
StartPos = new(PosHorizontal, PosVertical + 2),
EndPos = new(PosHorizontal, ConsoleWrapper.WindowHeight - 1),
Color = ConsoleColors.Lime,
};
var leftRuler = new Line()
{
DoubleWidth = false,
StartPos = new(0, PosVertical - 1),
EndPos = new(PosHorizontal - 4, PosVertical - 1),
Color = ConsoleColors.Lime,
};
var rightRuler = new Line()
{
DoubleWidth = false,
StartPos = new(PosHorizontal + 4, PosVertical - 1),
EndPos = new(ConsoleWrapper.WindowWidth - 1, PosVertical - 1),
Color = ConsoleColors.Lime,
};

// Check the ruler states
if (topRuler.EndPos.Y >= topRuler.StartPos.Y)
lineBuilder.Append(topRuler.Render());
if (bottomRuler.EndPos.Y >= bottomRuler.StartPos.Y)
lineBuilder.Append(bottomRuler.Render());
if (leftRuler.EndPos.X >= leftRuler.StartPos.X)
lineBuilder.Append(leftRuler.Render());
if (rightRuler.EndPos.X >= rightRuler.StartPos.X)
lineBuilder.Append(rightRuler.Render());

// Render the bars
TextWriterRaw.WriteRaw(lineBuilder.ToString());
}

// Reset resize sync
ConsoleResizeHandler.WasResized();
ScreensaverManager.Delay(ScreensaverPackInit.SaversConfig.PointTrackDelay);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override void ScreensaverLogic()
int Height = ConsoleWrapper.WindowHeight - 4;
int Width = ConsoleWrapper.WindowWidth - 4;

// Then, go ahead and make these bars trails themselves.
// Then, go ahead and make these bars swivel themselves.
List<int> CurrentPosVertical = [];
List<int> CurrentPosHorizontal = [];
double FrequencyVertical = Math.PI / ScreensaverPackInit.SaversConfig.TrailsVerticalFrequencyLevel;
Expand Down
Loading

0 comments on commit fb44a03

Please sign in to comment.