Created an Easy Console Wave Pattern

So this console program I made prints out a moving wave onto the screen.
This demonstrates that you can create simple graphics with the console (although slow and cumbersome).

Since removing characters from the string is faster than adding them, the wave is sort of choppy at the positive slopes.

I still don't know how to make the wave appear smoother, since right now its a triangle shape. I'm assuming at first I'll substract/add the characters 1 at a time, and as time goes on 2, and 3 at a time, since the real sin wave has increasing and decreasing slope.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>
#include <Windows.h> // need this for the Sleep() function
using namespace std;

void wave(){
	//declarations
	string wave;
	string::iterator point; //allows us to scan through a string I guess?
	char letter;
	int length, time, i=0, j=0;

	cout << "How tall shall the wave be? (Please keep it under 100) ";
	cin >> length;
	cout << "How fast shall the wave move? (Hint: 1000 = 1 second) ";
	cin >> time;
	cout << "What will the wave look like? (Only 1 character please) ";
	cin >> letter;
	while(j<=length){ // Initialize string length
		wave+=letter;
		j++;
	}

	for(i=0;;i++){ //remove character at the end of the string
		point=wave.begin()+wave.size()-1; 
		wave.erase(point);
		Sleep(time); //This might be bad practice in the industry
		cout << wave << endl;
		if(wave.size()==1){ //add character at the end of the string
			for(i=0;;i++){
				Sleep(125);
				wave+=letter;
				cout << wave<<endl;
				if(wave.size()==length){
					break;
				}
			}
		}
	}
}

int main(){
   wave();
   system("pause"); //This is bad practice in the industry
}
Last edited on
Topic archived. No new replies allowed.