Skip to content

Commit

Permalink
Update a lot
Browse files Browse the repository at this point in the history
Added more member variables to Raindrop
Added more parameters to Raindrop constructor
Changed some parameters in Raindrop constructor
Updated Raindrop.Update() and Raindrop.Render()
Updated how Raindrops are spawned in Main(). Notably, they can spawn in the middle of the screen now
Formatted Program.cs and Raindrop.cs
  • Loading branch information
Squaduck committed Jul 5, 2024
1 parent 58fc354 commit 6de1dcd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
31 changes: 28 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,34 @@ public static void Main(string[] args)

CharBuffer.Fill(BlankChar);

while(Random.Shared.Next(2) == 0)
Raindrops.Add(new(TrailLength, CurrentTermSize.cols, HSL_Util.HSLtoRGB(new(Random.Shared.NextDouble() * 360d, 1d, 0.6d)), ActiveRaindropCharCol));

for (int i = 0; i < CurrentTermSize.cols; i++)
{
if (Random.Shared.NextSingle() < 0.015f) // Flat 1.5% chance for every column every update. Feels a little slow at small window sizes.
{
// 90% chance that it starts from the top. 10% chance it starts somewhere random in the top half of the window. (Potentially still the top.)
if (Random.Shared.NextSingle() < 0.9f)
{
Raindrops.Add(new(TrailLength, i, HSL_Util.HSLtoRGB(new(Random.Shared.NextDouble() * 360d, 1d, 0.6d)), ActiveRaindropCharCol));
}
else
{
int StartingLine = Random.Shared.Next(CurrentTermSize.lines / 2);
// The rendering order relies on the fact that items in the list are ordered by age, naturally putting newer, higher raindrops later in the list.
// Putting raindrops in with any other order would break the overlapping.
// The following code *should* insert the new raindrop at the right-ish point in the list.
// I haven't seen any issues with it, but this is just my first attempt at writing it and it may be wrong.
for (int j = 0; j <= Raindrops.Count; j++)
{
if (j + 1 >= Raindrops.Count | Raindrops[^(j + 1)].Line > StartingLine)
{
Raindrops.Insert(Raindrops.Count - (j + 1), new(TrailLength, i, HSL_Util.HSLtoRGB(new(Random.Shared.NextDouble() * 360d, 1d, 0.6d)), ActiveRaindropCharCol, StartingLine));
break;
}
}
}
}
}

for (int i = 0; i < Raindrops.Count; i++)
{
if (Raindrops[i].IsInBounds(CurrentTermSize))
Expand Down
48 changes: 29 additions & 19 deletions Raindrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,35 @@ public class Raindrop
// A bunch of random characters that exist in the font 'Hack'
// I've removed some that were quite small, but I can't be bothered to prune these more.
const string RaindropChars = "!#$%&()*+-/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^abcdefghijklmnopqrstuvwxyz{|}~¡¢£¤¥§©ª«®±µ¶·º»¼½¿ÀÃÄÅÆÇÈÊËÌÎÏÐÑÒÔÕÖ×ØÙÛÜÝÞßàâãäåæçèêëìîïðñòôö÷øùûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƒƠơƤƯưΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώϴ϶ЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџѢѣѲѳҐґҒғҔҕҖҗҘҙҚқҢңҤҥҪҫҬҭҮүҰұҲҳҺһӀӁӂӃӄӇӈӋӌӏӐӑӒӓӔӕӖӗӘәӚӛӜӝӞӟӠӡӢӣӤӥӦӧӨөӪӫӬӭӮӯӰӱӲӳӴӵӶӷӸӹԐԑԚԛԜԝԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔՕՖաբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփքօֆև։฿აბგდევზთიკლმნოპჟრსტუფქღყშჩცძწჭხჯჰჱჲჳჴჵჶჷჸჹჺẀẁẂẃẄẅẼẽỲỳỸỹ†‡•‣‰‹›‼‽⁅⁆⁇⁈⁉⁋₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₷₸₹№™Ω⅐⅑⅓⅔⅕⅖⅗⅘⅙⅚⅛⅜⅝⅞⅟←↑→↓↔↕↖↗↘↙↚↛↜↝↞↟↠↡↢↣↤↥↦↧↨↩↪↫↬↭↮↯↰↱↲↳↴↵↶↷↸↹↺↻↼↽↾↿⇀⇁⇂⇃⇄⇅⇆⇇⇈⇉⇊⇋⇌⇍⇎⇏⇐⇑⇒⇓⇔⇕⇖⇗⇘⇙⇚⇛⇜⇝⇠⇡⇢⇣⇤⇥⇦⇧⇨⇩⇫⇬⇭⇮⇯⇰⇱⇲⇳⇴⇵⇶⇷⇸⇹⇺⇻⇼⇽⇾⇿∀∁∂∃∄∅∆∇∈∉∊∋∌∍∎∏∐∑−∓∕∗∘∙√∛∜∝∞∟∠∣∧∨∩∪∫∬∭∴∵∶∷∸∹∺∻∼∽≁≂≃≄≅≆≇≈≉≊≋≌≍≎≏≐≑≒≓≔≕≖≗≘≙≚≛≜≝≞≟≠≡≢≣≤≥≦≧≨≩≭≮≯≰≱≲≳≴≵≶≷≸≹≺≻≼≽≾≿⊀⊁⊂⊃⊄⊅⊆⊇⊈⊉⊊⊋⊍⊎⊏⊐⊑⊒⊓⊔⊕⊖⊗⊘⊙⊚⊛⊜⊝⊞⊟⊠⊡⊢⊣⊤⊲⊳⊴⊵⊸⋂⋃⋄⋅⋆⋍⋎⋏⋐⋑⋚⋛⋜⋝⋞⋟⋠⋡⋢⋣⋤⋥⋦⋧⋨⋩⋯⌄⌈⌉⌊⌋⌐⌠⌡⎛⎜⎝⎞⎟⎠⎡⎢⎣⎤⎥⎦⎧⎨⎩⎪⎫⎬⎭⎮─━│┃┄┅┆┇┈┉┊┋┏┓┗┛┣┫┳┻╋╍╏═║╒╓╔╕╖╗╘╙╚╛╜╝╞╟╠╡╢╣╤╥╦╧╨╩╪╫╬╭╮╯╰╱╲╳╸╹╺╻▀▁▄▇▊▐░▓■▢▪▮▯▰▱▲△▴▵▶▷▸▹►▻▼▽▾▿◀◁◂◃◄◅◆◇◈◉◊○◌◍◎●◐◑◒◓◔◕◖◗◘◙◚◛◜◝◞◟◠◡◢◣◤◥◦◧◨◩◪◫◬◭◮◯◰◱◲◳◴◵◶◷◸◹◺◻◼◿♪❖❨❩❪❫❬❭❮❯❰❱❲❳❴❵➘➚➜➠➢➤➩➪➫➬➭➮➯➱➲➳➴➵➶➷➸➹➺➻➼➽➾⟂⟅⟆⟜⟠⟦⟧⟨⟩⟪⟫⟵⟶⟷⦇⦈⦗⦘⧫⧺⧻⨀⨯⩪⩫⬅⬆⬇⬈⬉⬊⬋⬌⬍⬖⬗⬘⬙⬚⸘⸟⸢⸣⸤⸥⸮";
List <RGB_Char> Trail;
List<RGB_Char> Trail;

// Both starting from 0
readonly int Column;
int Line = 0;
public int Column { get; private init; }
public int Line { get; private set; }

readonly int TrailLength;

RGB_Col ColDecrement;
RGB_Col ActiveCharColor;
RGB_Col TrailStartingColor;

public Raindrop(int TrailLength, int NumColumns, RGB_Col TrailStartingColor, RGB_Col ActiveCharColor)
readonly int MaxTrailCharChanges;

/* IDEA:(s) for other variables */
// Background Color (Active and Trail)
// Trail Char 'Corruption' Chance
// More advanced trail color 'decrement' (Func<>?)
// Func<>(s) for color stuff in general. Could allow active color randomization, as an example.

public Raindrop(int TrailLength, int Column, RGB_Col TrailStartingColor, RGB_Col ActiveCharColor, int StartingLine = 0, int MaxTrailCharChanges = 3)
{
this.TrailLength = TrailLength;
Trail = new(TrailLength);
Column = Random.Shared.Next(NumColumns);
this.Column = Column;
this.ActiveCharColor = ActiveCharColor;
this.TrailStartingColor = TrailStartingColor;
this.MaxTrailCharChanges = MaxTrailCharChanges;
this.Line = StartingLine;

// Calculate how much to decrement the trail each step.
// This prevents us from easily changing a character to a different color in the middle of the trail.
Expand All @@ -50,15 +60,18 @@ public Raindrop(int TrailLength, int NumColumns, RGB_Col TrailStartingColor, RGB

public void Update()
{
if (Line != 0 ) // Don't operate on a trail that doesn't exist.
if (Trail.Count != 0) // Don't operate on a trail that doesn't exist.
{
// Potentially randomize a character
if (Random.Shared.Next(10) == 0)
// Potentially randomize some characters
for (int i = 0; i < MaxTrailCharChanges; i++)
{
int IndexToChange = Random.Shared.Next(Trail.Count);
RGB_Char CopiedChar = Trail[IndexToChange];
CopiedChar.Character = RaindropChars[Random.Shared.Next(RaindropChars.Length)];
Trail[IndexToChange] = CopiedChar;
if (Random.Shared.NextSingle() < 0.15f) // IDEA: Could make this a member variable and set in constructor. That could allow it to either be set as a paramater or by the trail length or something.
{
int IndexToChange = Random.Shared.Next(Trail.Count);
RGB_Char CopiedChar = Trail[IndexToChange];
CopiedChar.Character = RaindropChars[Random.Shared.Next(RaindropChars.Length)];
Trail[IndexToChange] = CopiedChar;
}
}

// Step each trail char down a bit
Expand All @@ -69,12 +82,14 @@ public void Update()
Trail[i] = CopiedChar;
}

// Make the last char green
// Make the last char part of the trail
{
RGB_Char CopiedChar = Trail[^1];
CopiedChar.FG_Col = TrailStartingColor;
Trail[^1] = CopiedChar;
}

Line++;
}

// Append new 'active' char
Expand All @@ -83,7 +98,6 @@ public void Update()
// Remove oldest trail char if length is too long.
if (Trail.Count > TrailLength)
Trail.RemoveAt(0);
Line++;
}

public void Render(Span<RGB_Char> CharBuffer, (int cols, int lines) TerminalSize)
Expand All @@ -92,11 +106,7 @@ public void Render(Span<RGB_Char> CharBuffer, (int cols, int lines) TerminalSize

for (int i = 0; i < Trail.Count; i++)
{
// Subtracting one here moves moves it up one line.
// This is necessary because Raindrop.Update() places the active character one line down.
// This caused the active character to start one line too far down.
// There is probably a better way to fix this, but this works fine.
int PosIndex = (Line - i - 1) * TerminalSize.cols + Column;
int PosIndex = (Line - i) * TerminalSize.cols + Column;

if (PosIndex >= 0 && PosIndex < CharBuffer.Length)
CharBuffer[PosIndex] = Trail[^(i + 1)];
Expand Down

0 comments on commit 6de1dcd

Please sign in to comment.