|
-
October 28th, 2007, 07:53 AM
#1
Drawing a sine wave into a 2d Array
Hi
I'm having trouble drawing a sinewave horizontally across the screen into an array[10][100]. The wave must be drawn using the '*' character.
I can initialize the array all to spaces but I can't figure out how to put the sinewave into it. I've been looking on the net and have been able to draw sinewaves that travel vertically down the page using this code:
array[49 + (int) (49 * sin(M_PI * (float) c / 10))] = '*';
printf("%s\n", array);
array[49 + (int) (49 * sin(M_PI * (float) c / 10))] = ' ';
I have it in a for loop and set it to 20 lines so it goes through one period. Unfortuantely I can't get it into my array of 10X100. My maths is crap so I can't figure out what calculation I need to create a sinewave horizontally into the array.
I want it to look something like this at run time, (without the zeros, I had to put them in otherwise the post ignored the spaces I put in and bunched all the '*' up together!).
0000000000*000000000000000000000000000000000
000000*0000000*00000000000000000000000000000
000*0000000000000*00000000000000000000000000
*000000000000000000*00000000000000000000000*
000000000000000000000*0000000000000000000*00
00000000000000000000000*000000000000000*0000
0000000000000000000000000*00000000000*000000
0000000000000000000000000000*000000*00000000
00000000000000000000000000000000*00000000000
I'd also like to be able to manipulate the equation so that I can fit 2 cycles into the same space, then 3 and 4 and 5. That I think I can figure out, but any help on how to fit one sinewave period into my array would be most helpful.
Thank you for your time and help.
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|