We used to use FORTRAN programs on mainframe comnputers to plot graphs on line printers. Some SPICE programs still do this. It is just a matter of constructing the strings with blanks and asterisks and writing them to an output stream.Originally posted by BladeSabre@Jun 1 2006, 12:59 PM
1. What do you mean by "draw a sine wave ... without using graphics"?
2. C++ does not have its own graphics, and the code varies wildly depending on whether you're using the operating system's routines or some cross-platform library. Have you used any kind of graphics before? What did you use?
[post=17442]Quoted post[/post]
Originally posted by BladeSabre@Jun 1 2006, 11:59 AM
1. What do you mean by "draw a sine wave ... without using graphics"?
2. C++ does not have its own graphics, and the code varies wildly depending on whether you're using the operating system's routines or some cross-platform library. Have you used any kind of graphics before? What did you use?
[post=17442]Quoted post[/post]
Originally posted by BladeSabre@Jun 2 2006, 10:54 AM
OK, so the answer to my second question is that you're using "graphics.h" for your graphics. I know roughly what that is, though I can't help you with code for it.
"Using loop to display a character in sine wave form" does not make any more sense to me than before. Are you intending to draw using a grid of characters, like what Papabravo suggested?
[post=17468]Quoted post[/post]
#include <math.h>
#include <stdio.h>
#define ROWS 22
#define COLS 72
#define ZERO_LINE_ROW 10
#define VALUE_PER_ROW 0.1
#define RADS_PER_COL 0.5
#define STARTING_RADS 2.0
void drawwave (char grid[][COLS+1]) {
int row, col;
double x, y;
for (row = 0; row < ROWS; row++) {
for (col = 0; col < COLS; col++) {
grid[row][col] = ' ';
}
grid[row][COLS] = '\0';
}
for (col = 0; col < COLS; col++) {
x = STARTING_RADS + (RADS_PER_COL * col);
y = sin(x);
row = ZERO_LINE_ROW - (int) (y / VALUE_PER_ROW);
if (row >= 0 && row < ROWS) {
grid[row][col] = '*';
}
}
}
int main (int argc, char*argv[]) {
char grid[ROWS][COLS+1];
int row;
drawwave(grid);
for (row = 0; row < ROWS; row++) {
puts (grid[row]);
}
getchar();
return 0;
}
by Aaron Carman
by Aaron Carman
by Jake Hertz