Introduction
I like to make surprises and gifts to the people I value or want to impress. I rarely do them because I expect something in return. One reason for that is that I enjoy the creativity process. Usually, the result is a unique present. When I give/send it to the target person, usually he/she really likes it. Most people lack creativity and give gifts to their (girl/boy)friends only when there is some special occasion. Usually, these presents are trivial - flowers, chocolate bonbons, plush toys, etc. So I decided to create a new series dedicated to giving you more creative ideas - Geeks Gifts Series.
What Is the Gift's Idea?
It was Valentines Day, and I wanted to create something interesting for a girl. I buy flowers too, but it is too banal. So I decided to create an application that displays flowers in a unique way. When the girl types a letter from her name, the program shows a flower in a different color. The cool stuff here is that it was an old-school console app.
ASCII Art Flowers Program Code
I built two versions of the app - a simple and an improved one. You can modify them as you like. As you will notice the name of the girl is hard-coded so for obvious reasons, I changed it (it is not Qwert :D).
I love the ASCII art - creating figures with ASCII characters. Of course, I didn't reinvent the wheel, and I didn't create the flower images manually. If you Google, you will find tonnes of ASCII string pictures. You can find lots of stuff on AsciiiWorld.com.
Simple Version
I had to built the program for half an hour so you understand why the code looks like this:
class Program
{
static void Main(string[] args)
{
string flower1 = @"
H H H H H
H H H H H H H H
H H H H H H H
H H H H H H H H H H
H H H H H H H H H H H
H H H H H H H H H H H H
H H H H H H H H H H H
H H H H H H H H H H H
H H H H H H H H H H H H
@ H H H H H H H H H H H H
@ @ H H H H H H H H H H H H H
@ @ H H H H H H H H H H H H H
@ @ @ H H H H H H H H H H H H
@ @ H H H H H H H H H H H H
@ @ @ H H H H H H H H H H @ @
@ @ H H H H @ H H H H H H @ @ @ @ @
@ @ H H H @ @ H H H H H @ @ @ @ @
@ @ @ H H H H @ @ H H H H H @ @ @
@ @ H H H H @ @ H H H H H @ @ @
@ H H H H @ @ @ H H H H H H @ @ @
H H H H @ @ H H H H H H @ @
H H H H @ @ H H H H H @ @ @
@ @ @ H H H H @ @ H H H H H H @ @
@ @ @ @ @ @ H H H @ @ @ H H H H H @ @ @
@ @ @ @ @ H H H @ @ @ H H H H @ @ @
@ @ @ @ @ H H H H @ @ @ H H H H H @ @ @
@ @ @ H H H @ @ @ @ H H H H @ @ @ @
@ @ @ H H H @ @ @ H H H H @ @ @
@ @ @ H H @ @ @ @ H H H @ @
@ @ H H @ @ @ @ H H @ @ @
@ @ @ H @ @ @ @ @ H @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @
@ @ @ @ @
@ @ @
@ @ @ @ @ @
@ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @
@ @ @ @
@ @ @ @
";
string flower2 = @"
%%%%%%
%%%%%%
&&%%%%%
' %%%%%
' %%%%
'' %%%%
' ' %%%%
' ' %%%%
' ' %%%%
' ~~ ' %%%%
' ~~ ~~ ' %%%%
' ~~~ ~~~ ' %%%%
' ~~~~~ ~~~~ ' %%%%
' ~~~~~ ~~~~~ ' %%%%
' ~~~~~ ~~~~ ' &&&&&&&
` ~~~ ~~~ ' {{}}{{}}{{}}
` ~~~ ~~ ' / \
` ~~~ ' / /\ \
` ' / \
`' / / \ \
/ \
/ / \ \
/ \
\ / \ / \ /
.... .... ....
|| \\
|| \\
|| \\
o o oo o o
oo oo oo
o o o
";
string flower3 = @"
__ .---.
__ / ` .-.7,--.
/ `. .-''. -, , \
'--.- -; | ) /
,` / \ ,_) / '-.
/ ( ( | / .' ) \
'. `--,/ .---' ,-.|
`--. / '-, -' .'
.==,=; `-,.;--'
/ ,' _;--;|
/_...=' ||
jgs || .==,=.
||/ '.\
,||`'=...__\
||
||
||,
||
||
||
";
string flower4 = @"
.=====__
/==Z' .===_ ~~=,_===\
_/ | | YZ, `\, ~\
| | | _/=j'\ !, d
__====_| | b/ V`; /' .M ,
`5\==/~~ W, t d+, .D4| / /'|/~~~\=__ .-
`\ t~\ | |t`~~T/'|Z :/ | ~~\=/V
\ | \4, | ~/~' :Z -! | |
\, /\__| \\.! :XG \ / ._, ./'
`L | ~; V; _//' | \ .f~' `~; .b_
./ \\__JL `; Y7~ | / / d //' \,
.! `D\, `\, | .! .t/ .(_/=~ \
/ `;`~~~=+=qLb, jK_L==f' j'' `;
./ .(r, `~\5' ~\\,._r/ |
~=m! ./D' `\, \, !G~ t
~==___===/'/ .!`\__ /! __=~\\~=_ TG=
| .| ~\=\=r@/~5 \ !, ~=_, __//'
|./~V || `| \, t ~~~~\==~~
t| | | | | !\, \=_,
! t .! !, \ `\/~~~
| / !\/\
`; ./ `~-
t .!
N, ./'
`\/'";
string flower5 = @"
.@. .
@m@,. .@
.@m%nm@,. .@m@
.@nvv%vnmm@,. .@mn%n@
.@mnvvv%vvnnmm@,. .@mmnv%vn@,
@mmnnvvv%vvvvvnnmm@,. .@mmnnvvv%vvnm@
@mmnnvvvvv%vvvvvvnnmm@, ;;;@mmnnvvvvv%vvvnm@,
`@mmnnvvvvvv%vvvvvnnmmm;;@mmnnvvvvvv%vvvvnmm@
`@mmmnnvvvvvv%vvvnnmmm;%mmnnvvvvvv%vvvvnnmm@
`@m%v%v%v%v%v;%;%;%;%;%;%;%%%vv%vvvvnnnmm@
.,mm@@@@@mm%;;@@m@m@@m@@m@mm;;%%vvvnnnmm@;@,.
.,@mmmmmmvv%%;;@@vmvvvvvvvvvmvm@@;;%%vvnnm@;%mmm@,
.,@mmnnvvvvv%%;;@@vvvvv%%%%%%%vvvvmm@@;;%%mm@;%%nnnnm@,
.,@mnnvv%v%v%v%%;;@mmvvvv%%;*;*;%%vvvvmmm@;;%m;%%v%v%v%vmm@,.
,@mnnvv%v%v%v%v%v%v%;;@@vvvv%%;*;*;*;%%vvvvm@@;;m%%%v%v%v%v%v%vnnm@,
` `@mnnvv%v%v%v%%;;@mvvvvv%%;;*;;%%vvvmmmm@;;%m;%%v%v%v%vmm@' '
`@mmnnvvvvv%%;;@@mvvvv%%%%%%%vvvvmm@@;;%%mm@;%%nnnnm@'
`@mmmmmmvv%%;;@@mvvvvvvvvvvmmm@@;;%%mmnmm@;%mmm@'
`mm@@@@@mm%;;@m@@m@m@m@@m@@;;%%vvvvvnmm@;@'
,@m%v%v%v%v%v;%;%;%;%;%;%;%;%vv%vvvvvnnmm@
.@mmnnvvvvvvv%vvvvnnmm%mmnnvvvvvvv%vvvvnnmm@
.@mmnnvvvvvv%vvvvvvnnmm'`@mmnnvvvvvv%vvvnnmm@
@mmnnvvvvv%vvvvvvnnmm@':%::`@mmnnvvvv%vvvnm@'
@mmnnvvv%vvvvvnnmm@'`:::%%:::'`@mmnnvv%vvmm@
`@mnvvv%vvnnmm@' `:;%%;:' `@mvv%vm@'
`@mnv%vnnm@' `;%;' `@n%n@
`@m%mm@' ;%;. `@m@
@m@' `;%; `@
`@' ;%;. '
";
var key = new ConsoleKeyInfo();
while (!System.Console.KeyAvailable && key.Key != ConsoleKey.Escape)
{
System.Console.ForegroundColor = ConsoleColor.White;
System.Console.WriteLine();
System.Console.Write("Enter a letter part of your name (Qwert) (quit = ESC): ");
key = System.Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.Q:
System.Console.ForegroundColor = ConsoleColor.Red;
System.Console.WriteLine(flower1);
break;
case ConsoleKey.W:
System.Console.ForegroundColor = ConsoleColor.Blue;
System.Console.WriteLine(flower2);
break;
case ConsoleKey.E:
System.Console.ForegroundColor = ConsoleColor.DarkYellow;
System.Console.WriteLine(flower3);
break;
case ConsoleKey.R:
System.Console.ForegroundColor = ConsoleColor.DarkCyan;
System.Console.WriteLine(flower4);
break;
case ConsoleKey.T:
System.Console.ForegroundColor = ConsoleColor.DarkGray;
System.Console.WriteLine(flower5);
break;
default:
if (System.Console.CapsLock && System.Console.NumberLock)
{
System.Console.WriteLine(key.KeyChar);
}
break;
}
}
}
}
First the flowers are presented as string
s. Then there is a loop where the girl types a character if it is a letter from her name, the program displays on the console the corresponding flower in different color. It stops once she clicks ESC.
Improved Version
I couldn't handle the simplicity of the code so I improved the initial version so that it can be more scalable.
FlowersExecutionEngine
I moved the execution of the display logic to this static
class.
public static class FlowersExecutionEngine
{
public static void Execute(List<Flower> flowers)
{
var key = new ConsoleKeyInfo();
while (!System.Console.KeyAvailable && key.Key != ConsoleKey.Escape)
{
System.Console.ForegroundColor = ConsoleColor.White;
System.Console.WriteLine();
System.Console.Write(value: "Enter a letter part of your name (Qwert) (quit = ESC): ");
key = System.Console.ReadKey(intercept: true);
Flower flowerToBePrinted = flowers.FirstOrDefault(f => f.Letter == key.Key);
flowerToBePrinted?.Print();
}
}
}
Base Flower
Now every flower should have the ASCII image, a color and a letter. The Print
method changes the foreground color of the console and prints the flower image to it.
public abstract class Flower
{
public Flower(ConsoleColor color, ConsoleKey letter)
{
this.Color = color;
this.Letter = letter;
}
public abstract string FlowerPicture { get; }
public ConsoleColor Color { get; set; }
public ConsoleKey Letter { get; set; }
public void Print()
{
System.Console.ForegroundColor = this.Color;
System.Console.WriteLine(this.FlowerPicture);
}
}
Concrete Flower
The concrete flower classes only override and assign the ASCII flowers' images.
public class TypeThreeFlower : Flower
{
public TypeThreeFlower(ConsoleColor color, ConsoleKey letter) : base(color, letter)
{
}
public override string FlowerPicture
{
get
{
return @"
__ .---.
__ / ` .-.7,--.
/ `. .-''. -, , \
'--.- -; | ) /
,` / \ ,_) / '-.
/ ( ( | / .' ) \
'. `--,/ .---' ,-.|
`--. / '-, -' .'
.==,=; `-,.;--'
/ ,' _;--;|
/_...=' ||
jgs || .==,=.
||/ '.\
,||`'=...__\
||
||
||,
||
||
||
";
}
}
}
Program
The main program body is now shorter compared to the initial version. You need to create all of the flowers and pass them to the flowers execution engine.
class Program
{
static void Main(string[] args)
{
var flowers = new List<Flower>()
{
new TypeOneFlower(ConsoleColor.Red, ConsoleKey.Q),
new TypeTwoFlower(ConsoleColor.Blue, ConsoleKey.W),
new TypeThreeFlower(ConsoleColor.DarkYellow, ConsoleKey.E),
new TypeFourFlower(ConsoleColor.DarkCyan, ConsoleKey.R),
new TypeFiveFlower(ConsoleColor.DarkGray, ConsoleKey.T),
};
FlowersExecutionEngine.Execute(flowers);
}
}
Finish the Surprise- Add an Icon
In order for your surprise to look more complete, you need to change the icon for your app. You will find lots of sites for free icons. For example - FlatIcon.com. After you download the most appropriate one, open the properties of the project file and change the icon from the Application tab (Resources section).
So Far in the "Geek Gifts Series" Series
- Geeks Gifts: Surprise a Girl with Cats or Flowers Wallpaper Changing App
The post Geeks Gifts: Surprise a Girl with ASCII Art Flowers Program appeared first on Automate The Planet.
All images are purchased from DepositPhotos.com and cannot be downloaded and used for free.
License Agreement