How to create a screensaver in Core C#

This program was written as an old style screensaver as a part of a training course. The screen saver is a simple program which uses random numbers to display dots on screen in different colors. It also uses a simple logic to keep removing dots by overwriting them with blank spaces, so that the screen does not fill up. There is a for loop to slow down the appearance of dots, i.e., stars.
This code is not the last code, suggestions and improvements are welcome.
Note: The % operator is used to generate actual randomness on screen, using many if-elses. Only later was it discovered that one can also pass a seed number for effective random values.
Note: This program generates only 10000 times. One can also pass a command line argument to run the loop indefinitely and prompt user to press Control+c to exit from the program.

using System;
class set_cursor2
int lastnum;

private int RandomNumber(int min, int max)
Random random = new Random();
lastnum = random.Next(min, max);

if (lastnum%3 == 0 || lastnum%4==0 )
lastnum = random.Next(min, max);

if (lastnum%5 == 0 || lastnum%6==0 || lastnum%7==0 )
lastnum = random.Next(min, max);

return lastnum;

static void Main(string[] args)
set_cursor2 obj = new set_cursor2();
int lastrow,lastcol;
int i,j,t;
Console.BufferHeight = 500;
Console.BufferWidth = 200;
Console.CursorSize = 50;
Console.CursorVisible = true;

i = 1;
j= obj.RandomNumber(1,99);
Console.CursorLeft = j;
lastcol = j;
j= obj.RandomNumber(1,49);
lastrow = j;
Console.CursorTop = j;
if (i%3 == 0)
Console.ForegroundColor = ConsoleColor.White;
else if (i%4 == 0)
Console.ForegroundColor = ConsoleColor.Cyan;
Console.ForegroundColor = ConsoleColor.DarkBlue;

if ((i+j) % 2 == 0 || (i+j) % 3 == 0 || (i+j) % 5 == 0)
Console.WriteLine(" ");

// Console.WriteLine(". {0} {1}",lastrow,lastcol);

while (i<=10000);
Console.WriteLine("\n\n Finish");

Anyone can use the color codes to change the layout of the screen. The following are some popular color codes:

Color Description
Black The color black.
Blue The color blue.
Cyan The color cyan (blue-green).
DarkBlue The color dark blue.
DarkCyan The color dark cyan (dark blue-green).
DarkGray The color dark gray.
DarkGreen The color dark green.
DarkMagenta The color dark magenta (dark purplish-red).
DarkRed The color dark red.
DarkYellow The color dark yellow (ochre).
Gray The color gray.
Green The color green.
Magenta The color magenta (purplish-red).
Red The color red.
White The color white.
Yellow The color yellow.

28 responses to this post.

  1. Posted by Nakshtra Choudhary on March 9, 2012 at 4:32 pm

    Seems a very old style of code and standards, can you develop it in new way?

  2. Posted by Nakshtra Choudhary on March 9, 2012 at 4:33 pm

    actually using this my system seems to be feeling headache, so please make it low memory consuming.

  3. I am impressed with this website, real I am a fan.

  4. I enjoy you because of all your valuable effort on this web site. Betty enjoys making time for research and it’s simple to grasp why. My partner and i know all regarding the dynamic medium you give worthwhile guides by means of this website and as well invigorate contribution from others on that subject then our simple princess is certainly discovering a whole lot. Take advantage of the rest of the new year. You are performing a really good job.

  5. you really think so?

  6. I appreciate your helpful blog. super work. I hope you produce more. I will carry on watching

  7. I adored your rich site. topnotch stuff. I hope you release more. I will carry on subscribing

  8. Of course I like your website, however you need to check the spelling on several of your posts. Several of them are rife with spelling problems and I find it very silly to inform you. Nevertheless I’ll definitely come again again!

  9. Web hosting getting cheaper with offering good functionalities.I have tried some Awesome web hosting providers and found them great

  10. Fantastic template and customizable … well more of controlled choice really. I keep getting an IO error after i embed it on my Joomla web page. Still I appreciate the effort.

  11. Here go some answers to questions raised above:

  12. Nice post ! Cheers for, posting on this blog page dude! I shall email you soon. I did not realise that!

  13. Can you message me with some pointers about how you made this blog site look this good, I would be appreciative!

  14. Oh man. This blog site is cool! How can I make it look this good !?

  15. Whenever I initially commented I clicked on the Notify me any time new comments are added checkbox and currently each and every time a remark is added I receive 4 emails with the exact same comment.

  16. Jesus Christ theres lots of spammy feedback on this website. Have you ever thought about trying to eliminate them or installing a plugin?

  17. If you could message me with some hints & tips on how you made this website look this cool , Id appreciate it!

  18. Awesome post . Thank you for, writing on my blog mate! I shall email you some time! I didnt realise that!

  19. Even though I truly like this publish, I believe there was an spelling error shut towards the finish with the third section.

  20. How do you make a site look this sick!? Email me if you want and share your wisdom. Id be appreciative!

  21. Do you have a spam concern on this website; I also am a blogger, and I was asking yourself your scenario; weve got created some great strategies and we are looking to trade options with other folks, be certain to fire me an e-mail if planning to pursue.

  22. This really solved my problem, thank you!

  23. I Am Going To have to visit again when my course load lets up – however I am taking your Feed so i could go through your internet site offline. Thanks.

  24. I have got one recommendation for your webpage. It appears like at this time there are a couple of cascading stylesheet troubles when opening a selection of webpages within google chrome as well as safari. It is operating fine in internet explorer. Possibly you can double check this.

  25. I have got one recommendation for your webpage. It seems like there are a few cascading stylesheet troubles when launching a selection of web pages in google chrome as well as firefox. It is operating fine in internet explorer. Possibly you can double check this.

  26. I tried taking a look at your website with my iphone and the layout does not seem to be right. Might want to check it out on WAP as well as it seems most mobile phone layouts are not working with your web page.

  27. I believe one of your current ads triggered my internet browser to resize, you may well need to put that on your blacklist.

  28. Just discovered this site thru Google, what a way to brighten up my year!

Comments are closed.

%d bloggers like this: