It's more useless than bad I think. It sets the background to all the listed colors with no delay, so the user just sees at best what looks like a brief glitch. With the background ending up white.
It would make more sense to have a small function to do the repetitive bit (colour->clear to force background update) by taking a colour as an argument, then you could loop over an array or dictionary that calls it for each colour. It'd be less repetitive, potentially useful in other places (since you'd have a small background-set function that works elsewhere), and you could also do new patterns easily as well. You'd probably want some kind of delay to make it more visible, too.
If it's a one-off thing it doesn't really matter beyond being more code to scroll through, though.
repeating yourself like that is a bad idea, you could do that with a loop. let's also not forget the fact that there's no delay at all so it'll look like a 20ms seizure
Honestly not too sure myself, though there are more elegant ways to do the same thing if you just want a simple color cycling this is fine and pretty straightforward
That script wouldn't be colour cycling anything. It would run in ms and your unlikely to see anything other than the final colour. It needs delays or scrapping altogether.
Imo that's not it, unless you do need the blending. Enums are mapped to numbers in C#, so you can cast the integer used to loop without creating a list.
If you don't care about the order then sure, even better. In C# you can even do Enum.GetValues<T>() and retain type safety and skip the casting.
Points 2 and 3 still stand though. You'd only want this explicitly in a list (as per point 1) in case you don't want all elements from the array and/or the order matters.
As vexille said here, you can use Enum.GetValues<T>(), which returns an array that contains the values of the constants in said enum type. With that you could use a foreach loop and still avoid manually creating an array.
Would probably, if I was trying to make a rainbow effect I'd blend between all the colors in the color wheel using some simple math but I don't think that would work very well here, but if you're only having like 10 colors this solution ig is fine
I think it's just bad code in the sense that it might cause epilepsy (but BTH I have no clue if epilepsy can be cause this way, just having fast random flashing lights can't be good)
Everyone's epilepsy is different. Some may only be triggered by certain frequencies. Some may only trigger from certain colours. Its a superfluous piece of code that brings nothing beneficial for the end user but runs the risk of breaching equality laws if someone's epilepsy is triggered (at least in the UK).
However, to give the coder some credit, it appears this is some kind of config script so the user can set whether this runs or not. Setting it to run by default would raise epilepsy concerns but we can't tell this from the code snippet provided.
It would make sense if there was a delay but its still a pointless piece of code that brings zero benefit to an end user. I'm guessing this was intended as an Easter egg.
An "OS"? As in, someone made a program called an "OS" for C# terminals when it's no more than a very simple shell? Didn't think my "OS" rant for ComputerCraft would be relevant for other languages, but I stand corrected I guess.
But you can do things such as call PC speaker, networking with raw IP, use Timer make multitasking etc. Do you really think making an OS with a useful standard library is not an OS? And this doesn't even seem like that much hand-holding, just the equivalent of some write to memory that could easily with the same amount of lines in C use pointer syntax, although rather use loop
Actually the ConsoleColor Enum is mapped to int values. These represent the old 4 bit colorspace of Windows and OS/2. Which is itself based on VGA Text Mode.
So the values do adhere to a system.
The least significant 3 bits determine hue:
bit 1 (value 1) is blue
bit 2 (value 2) is green
bit 3 (value 4) is red
So cyan would be bits 1 and 2 set. So (1 | 2 == 3)
This is the value of
ConsoleColor.DarkCyan
And the msb (bit 4) signifies a binary brightness value (0=half brightness, 1=full brightness)
So bright cyan would be bits 1, 2 and 4 set, which is the integer value 11.
This is the value of
ConsoleColor.Cyan
So
Console.ForegroundColor = (ConsoleColor)11;
sets your text color to Bright Cyan.
So in a sense you can "interpolate" rgb. There is just one value on each "axis" to work with.
Honestly the only way I could think of fixing this (assuming it's some sort of load-in that flashes all the colours to look fancy) would be to have all the colours have their own ID number (I'd be fairly surprised if that wasn't the case), and loop through that with a delay so it doesn't look like some kind of vbuffer garbage. Or alternatively forget the colour names and just increase the actual number itself.
163
u/TheTRCG Oct 04 '21
If it works it works
43
u/Taldoesgarbage Oct 04 '21
What's the point if the console gets cleared anyway??? (Kids, remember, use for loops & foreach loops)
48
u/Cloakknight Oct 04 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
22
u/JackMacWindowsLinux Oct 04 '21
An "OS"? As in, someone made a program called an "OS" for C# terminals when it's no more than a very simple shell? Didn't think my "OS" rant for ComputerCraft would be relevant for other languages, but I stand corrected I guess.
32
u/[deleted] Oct 04 '21
Why not just iterate through the enum using reflection and then set the background? 🥴🥴
5
u/Expert_Vehicle_7476 Oct 04 '21
Lmao this looks like something I would write on a late night
1
u/TheAwesome98_Real evil Oct 04 '21
An OS in C#?? how?
3
u/GiraffeMichael Oct 04 '21
Wait, is that Java?!?!?
1
u/jawsh_42 Oct 04 '21
How tf did they make an OS with C#
1
u/TheEmeraldFalcon Oct 09 '21
Honestly the only way I could think of fixing this (assuming it's some sort of load-in that flashes all the colours to look fancy) would be to have all the colours have their own ID number (I'd be fairly surprised if that wasn't the case), and loop through that with a delay so it doesn't look like some kind of vbuffer garbage. Or alternatively forget the colour names and just increase the actual number itself.