I am trying to write a program on generating a sinusoidal text in C. I tried the code below and got a vertical sine wave. Is it possible to make it horizontal? I am new to C programming, so if you could, please explain the code in simplest manner. Thank you!
#include <stdio.h>
#include <math.h>
int main()
{
// declarations
int x;
char y[80];
char str[] = "This is a test string";
// 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; str[x]!='\0'; x++)
{
y[40 + (int) (40 * sin(M_PI * (float) x /10))] = str[x];
printf("%s\n", y);
y[40 + (int) (40 * sin(M_PI * (float) x / 10))] = ' ';
}
// exit
return 0;
}
Output:
T
h
i
s
s
a
t
e
s
t
s
t
r
i
n
g
Is it possible to make the wave horizontal without changing the existing code? Thank you!