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
|
/*
* Copyright (C) 2018-2021 Miloš Stojanović
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#ifndef RAIN_H
#define RAIN_H
#include <string_view>
#include <utility>
#include <vector>
#include "Active.h"
#include "Color.h"
#include "DecimalFraction.h"
#include "RainColumn.h"
#include "RainStreak.h"
#include "Range.h"
#include "Terminal.h"
struct RainProperties {
Range<DecimalFraction> RainColumnSpeed;
Range<int> RainColumnStartingGap;
Range<int> RainColumnGap;
Range<int> RainStreakLength;
Range<int> MCharUpdateRate;
bool Fade;
Color CharacterColor;
Color BackgroundColor;
std::wstring_view Title;
};
class Rain : public Active {
std::vector<RainColumn> RainColumns;
const RainProperties Properties;
Terminal* terminal;
DecimalFraction GetRandomSpeed() const;
int GetRandomStartingGap() const;
public:
static constexpr RainProperties DEFAULT_PROPERTIES {
{{0, 5}, {1, 5}}, {10, 30}, {0, 40}, {1, 30}, {10, 20},
true, Color::GetColor("green"), Color::GetColor("black"),
L" T M A T R I X "
};
static constexpr RainProperties DENSE_PROPERTIES {
{1, 2}, {4, 9}, {4, 9}, {4, 20}, {5, 7},
false, Color::GetColor("green"), Color::GetColor("default"),
L" T M A T R I X "
};
static constexpr DecimalFraction MAX_FALL_SPEED {10};
static constexpr int MIN_LENGTH {1};
Rain(const RainProperties& RP, Terminal* T);
void Reset();
void Update() final;
virtual void UpdateStreakColors(RainStreak& rainStreak) const = 0;
int GetRandomLength() const;
int GetRandomGap() const;
std::pair<int, int> GetRandomUpdateRateAndTime() const;
};
class FadingRain final : public Rain {
public:
using Rain::Rain;
void UpdateStreakColors(RainStreak& rainStreak) const;
};
class NonFadingRain final : public Rain {
public:
using Rain::Rain;
void UpdateStreakColors(RainStreak& rainStreak) const;
};
#endif
|