change direction wave

Hi everybody.. i was make a sine graphic, but the result is not like what i want. Direction of sine wave that is in vertical, and amplitudo that is in horizontal. I want change the direction in horizontal and amplitudo in vertical. How i can do that? This is my source, thanks..

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
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <math.h>
// We need to output stuff, and we need the sine function
using namespace std;


int main(int argc, char *argv[])
{
// declarations
    int x;
    char y[80];

// setting entire array to spaces
    for(x = 0; x < 79; x++)
    y[x] = ' ';
    y[79] = '\0';

// print 20 lines, for one period (2 pi radians)
    for(x = 0; x < 20; x++)
    {
        y[30 + (int) (30 * sin(M_PI * (float) x / 10))] = '*';
        printf("%s\n", y);
        y[30 + (int) (30 * sin(M_PI * (float) x / 10))] = ' ';
    }

// exit
    system("PAUSE");
    return EXIT_SUCCESS;
}
Last edited on
Draw it to a temporary 2D array first, then print it out.


You should never try to use the console for graphics or games, by the way ;)
i'm sorry LB, i didn't understand what you mean exactly.. How can i Draw it to a temporary 2D array?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath>

int main()
{
    bool pixels[40][80] = {};
    for(unsigned i = 0; i < 80; ++i)
    {
        double pos = std::sin(2*3.1415926/80*i)*15+20;
        pixels[unsigned(pos)][i] = true;
    }
    for(unsigned r = 0; r < 40; ++r)
    {
        for(unsigned c = 0; c < 80; ++c)
        {
            std::cout << (pixels[r][c] ? '#' : ' ');
        }
        std::cout << std::endl;
    }
}
Demo: http://ideone.com/FfVVW
Notice that the Y axis is inverted - there are two ways you can fix this ;)
Last edited on
Thanks LB..;)
Topic archived. No new replies allowed.