Weekend Programming Challenge #3 24/02
4 posters
RUSES :: Programming :: Challenges
Page 1 of 1
Weekend Programming Challenge #3 24/02
Create a function that will animate a Flomb - all the arms change: \ -> / and / -> \ in each frame
i.e.
\(O_O)/ -> /(O_O)\
Let's say a rough parameter for the function is (C++)
void animateFlomb(const string& flomb, int numberOfFrames);
if animateFlomb("\(O__O\)",5) was called:
The output would be
\(O__O\)
/(O__O/)
\(O__O\)
/(O__O/)
\(O__O\)
Another function to create:
string flipHorizontalFlomb(const string& flomb)
This will flip a Flomb, but it's not a case of reversing the string because if:
\(O__O\) was reversed it would look like: )\O__O(\ which doesn't look right
Instead of flipping it like that, the function should flip it like:
\(O__O\) -> (/O__O)/
Then create a flipVerticalFlomb(const string& flomb)
\(O__O\) -> /(O__O/)
(flips the arms)
Using the basic ideas in the functions created
Make a function
void danceFlomb(const string& flomb, int numFrames)
That will flip the Flomb horizontally then vertically then horizontal... etc until the numFrames counter is reached
i.e.
danceFlomb("\(O__O\)",6) would output:
\(O__O\)
(/O__O)/
(\O__O)\
/(O__O/)
\(O__O\)
(/O__O)/
(repeats every 4 frames)
Also play around with clear screen commands (i.e. Windows only system("cls")) and wait commands to make an animation instead of a list of frames, and colouring the console (i.e. Windows: system("color AA") etc) so you could make a dance animation with lots of colours
i.e.
\(O_O)/ -> /(O_O)\
Let's say a rough parameter for the function is (C++)
void animateFlomb(const string& flomb, int numberOfFrames);
if animateFlomb("\(O__O\)",5) was called:
The output would be
\(O__O\)
/(O__O/)
\(O__O\)
/(O__O/)
\(O__O\)
Another function to create:
string flipHorizontalFlomb(const string& flomb)
This will flip a Flomb, but it's not a case of reversing the string because if:
\(O__O\) was reversed it would look like: )\O__O(\ which doesn't look right
Instead of flipping it like that, the function should flip it like:
\(O__O\) -> (/O__O)/
Then create a flipVerticalFlomb(const string& flomb)
\(O__O\) -> /(O__O/)
(flips the arms)
Using the basic ideas in the functions created
Make a function
void danceFlomb(const string& flomb, int numFrames)
That will flip the Flomb horizontally then vertically then horizontal... etc until the numFrames counter is reached
i.e.
danceFlomb("\(O__O\)",6) would output:
\(O__O\)
(/O__O)/
(\O__O)\
/(O__O/)
\(O__O\)
(/O__O)/
(repeats every 4 frames)
Also play around with clear screen commands (i.e. Windows only system("cls")) and wait commands to make an animation instead of a list of frames, and colouring the console (i.e. Windows: system("color AA") etc) so you could make a dance animation with lots of colours
Alex- Posts : 67
Join date : 2012-02-23
Location : Come at me bro
Re: Weekend Programming Challenge #3 24/02
Here's mine Criticism welcome.
http://pastebin.com/WWKV4pwE
http://pastebin.com/WWKV4pwE
- Spoiler:
- Code:
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
void animateFlomb(string , int );
string flipHorizontal(string );
string flipVertical(string );
void dance(string , int );
void rave(string , int );
string defaultFlomb = "\\(O__O\\)", flomb;
int main()
{
string option = "";
while(option != "exit")
{
cout << "Please choose a function to test..." << endl
<< "\t[1] animateFlomb (flipVertical)" << endl
<< "\t[2] dance (flipVertical and flipHorizontal)" << endl
<< "\t[3] rave ;)" << endl << endl << "> ";
cin >> option;
if(option == "1") // animateFlomb
{
animateFlomb(defaultFlomb, 5);
}
else if(option == "2") // dance
{
dance(defaultFlomb, 5);
}
else if(option == "3")
{
rave(defaultFlomb, 15);
}
else if(option != "exit")
{
cout << endl << "Please try again." << endl << endl;
}
}
return 0;
}
void animateFlomb(string input, int count)
{
system("color 0c");
flomb = defaultFlomb;
system("cls");
for(int i = 0; i < count; i++)
{
cout << endl << endl << endl << "\t\t" << flipVertical(flomb);
Sleep(500);
system("cls");
}
system("color 07");
}
string flipHorizontal(string input)
{
int size = input.length();
flomb = string(input.rbegin(), input.rend());
for(int i = 0; i < size; i++)
{
switch(flomb[i])
{
case '\\':
flomb.replace(i, 1, 1, '/');
break;
case '/':
flomb.replace(i, 1, 1, '\\');
break;
case '(':
flomb.replace(i, 1, 1, ')');
break;
case ')':
flomb.replace(i, 1, 1, '(');
break;
default:
break;
}
}
return flomb;
}
string flipVertical(string input)
{
int size = input.length();
flomb.clear();
for(int i = 0; i < size; i++)
{
switch(input[i])
{
case '\\':
flomb.replace(i, 1, 1, '/');
break;
case '/':
flomb.replace(i, 1, 1, '\\');
break;
default:
flomb.replace(i, 1, input, i, 1);
break;
}
}
return flomb;
}
void dance(string input, int count)
{
system("color 0c");
flomb = defaultFlomb;
system("cls");
for(int i = 0; i < count; i++)
{
for(int j = 0; j < 2; j++)
{
cout << endl << endl << endl << "\t\t" << flipVertical(flomb);
Sleep(500);
system("cls");
}
cout << endl << endl << endl << "\t\t" << flipHorizontal(flomb);
Sleep(500);
system("cls");
}
system("color 07");
}
void rave(string input, int count)
{
system("color 0c");
flomb = defaultFlomb;
system("cls");
for(int i = 0; i < count; i++)
{
switch(i)
{
case 1: case 6: case 11:
system("color 7d");
break;
case 2: case 7: case 12:
system("color 5a");
break;
case 3: case 8: case 13:
system("color 3f");
break;
case 4: case 9: case 14:
system("color 6d");
break;
case 5: case 10: case 15:
system("color 49");
break;
}
for(int j = 0; j < 2; j++)
{
cout << endl << endl << endl << "\t\t" << flipVertical(flomb);
Sleep(50);
system("cls");
}
cout << endl << endl << endl << "\t\t" << flipHorizontal(flomb);
Sleep(50);
system("cls");
}
system("color 07");
}
Charlie- Posts : 16
Join date : 2012-02-23
Re: Weekend Programming Challenge #3 24/02
looks amazing rave mode is best!!
cant wait to do some of these challenges
cant wait to do some of these challenges
Re: Weekend Programming Challenge #3 24/02
Might stop doing these cos no-one seems interested, answer code is on my netbook but Charlie's works fine
Alex- Posts : 67
Join date : 2012-02-23
Location : Come at me bro
Re: Weekend Programming Challenge #3 24/02
they are a realy good idea but just dont think anyone has the time at the moment
Re: Weekend Programming Challenge #3 24/02
Yeahh so busy at the moment :/ could be a good idea over easter or something?
ElliottH- Admin
- Posts : 16
Join date : 2012-02-23
Re: Weekend Programming Challenge #3 24/02
Yeah that sounds like a good idea actually, although revision could get in the way
Charlie- Posts : 16
Join date : 2012-02-23
Similar topics
» Daily Programming Challenge #1 22/02/12
» Daily Programming Challenge #2 23/02/12
» Programming Challenge #4 - Code Obfuscation
» Challenge Points
» Challenge Rules
» Daily Programming Challenge #2 23/02/12
» Programming Challenge #4 - Code Obfuscation
» Challenge Points
» Challenge Rules
RUSES :: Programming :: Challenges
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum