need to change this graph

heres my graph:

                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
              ooooooo                  │    ooooooo                       oooooo
            ooo      oo                │  ooo      oo                   ooo
           oo         oo               │ oo         oo                 oo
          oo           oo              │oo           oo               oo
────────ooo──────────────oo───────────ooo──────────────oo───────────oo──────────
       oo                 oo         oo│                oo         oo
      oo                   ooo      oo │                 ooo      oo
oooooo                       ooooooo   │                   ooooooo
  o                             o      │                      o
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │
                                       │


but i want to change it to look like this
http://www.google.ie/imgres?q=sine+wave+graph&hl=en&biw=1366&bih=587&gbv=2&tbm=isch&tbnid=oJ2eIa-eurAqkM:&imgrefurl=http://www.intmath.com/trigonometric-graphs/1-graphs-sine-cosine-amplitude.php&docid=UDPUCTbk1CVn-M&imgurl=http://intmstat.com/trigonometric-graphs/sinx.gif&w=328&h=207&ei=o3O-TuzZD4WnhAf3rNiNDA&zoom=1&iact=hc&vpx=482&vpy=184&dur=2137&hovh=165&hovw=262&tx=122&ty=108&sig=114339505897357424008&page=1&tbnh=97&tbnw=154&start=0&ndsp=21&ved=1t:429,r:2,s:0


so basically i want to get rid of the left side of the graph or maybe move the axis lines over and if possible put numbers on the x and y axis like in the other picture

heres the code:
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <math.h>


using namespace std;

float plot(float x);

float plot(float x)
{
    float y;
    
        y=sin(x);
    
    return y;
}

int main(int argc, char *argv[])
{

  int point[80][24];
  int j;
  float k,Pi;
  

  Pi=3.14159265358;
  
  for(int a=0;a<=24;a++)
  {
      for(int b=0;b<=80;b++)
      {
            point[b][a]=0;
      }
  }


  for(float i=-480;i<480;i++)
  {
      int z=int((i+480)/12);

      k = 12 + 4 *  -plot((i * Pi)/180);
      j=int(k);
      
      if (j <= 24 & j >0)
            point[z][j]=1;
  }   
  
  
  for(int y=1;y<=24;y++)
  {
      if (y == 12)
      for(int d=0;d<=79;d++)
            if (point[d][12] == 0)
                if (d==39)
                     cout << char(197);
                else
                     cout << char(196);
            else
				cout << "o";
      else
      {
            for(int x=0;x<=79;x++)
                  {
                        if (point[x][y] == 0)
                              if (x==39)
                                   cout << char(179);
                              else
                                   cout << " ";
                        else
                                  cout << "o";
                  }
      }
  }	
  return 0;
}
Last edited on
can anyone help here?
Given you were able to write the code above, I would have thought you'd find it easy enough to move the axis. You just need to tweak one of the conditions. (Line 67 looks like one place you need to change?)

And you should be able to use a simlar approach to decide whether to write a label rather than draw the graph. It would involve resizing and moving the graph a bit.

It might help to get a piece of old-fashioned graph paper and plan it out.

Andy

P.S. the plot() function is misnamed. It doesn't plot anything. In fact, it's just another name for sine in this case. Line 51-75 looks like a candidate for a function with that name.
Last edited on
ok thanks the graph isnt copying onto this properly but i moved the line over and now i want to get rid of the wave on the left side of the line. and is there a simple way to just put numbers along the axis lines?
Getting rid of the left hand side shold just be a case of starting to plot from e.g. x = 5 rather than 0. The you can use 0-4 for your label, with the same kind of logic. You want a label for the y axiz on rows 1, 12, 24 -- or whatever. when you start the row, format the number as a string (sprintf of ltoa) and then use the chars in the string rather than " ", "o", ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    for(int y=1;y<=24;y++)
    {
        for(int d=0;d<=4;d++)
        {
            // draw label
        }

        for(int d=5;d<=4;d++)
        {
            if (y == 12)
            {
                // draw axis, as above
            }
            else if (y >= 13 && y <= 15)
            {
                // draw label or line
            }
            else
            {
                // etc
            }
        }
    }
    


Or you could create an array of strings for the labels: most would be empty. This might be easier if you want to label the x axis. Unless you just want 3 labels, which will prob be easier to special case.
Last edited on
ok the graph didnt copy over right so the real graph doesnt look this bad
but i got the lines on top of the x axis to move over and i cant get the lines at the bottom to move over. any number in the for loops i change just causes the graph to change completely


     │
        │
        │
        │
        │
        │
        │
        │     ooooooo                       ooooooo                       ooooo
        │   ooo      oo                   ooo      oo                   ooo
        │  oo         oo                 oo         oo                 oo
        │ oo           oo               oo           oo               oo
───ooo──────────────oo───────────ooo──────────────oo───────────oo──────────
  oo                 oo         oo                 oo         oo
 oo│                  ooo      oo                   ooo      oo            oooo
o  │                    ooooooo                       ooooooo                o
   │                       o                             o
   │
   │
   │
   │
   │
   │
   │
   │
Have you added an extra condition? Your code draws this

     │
     │
     │
     │
     │
     │
     │
     │        ooooooo                       ooooooo                       oooooo
     │      ooo      oo                   ooo      oo                   ooo
     │     oo         oo                 oo         oo                 oo
     │    oo           oo               oo           oo               oo
─────┼──ooo──────────────oo───────────ooo──────────────oo───────────oo──────────
     │ oo                 oo         oo                 oo         oo
     │oo                   ooo      oo                   ooo      oo
oooooo                       ooooooo                       ooooooo
  o  │                          o                             o
     │
     │
     │
     │
     │
     │
     │


If I just change the conditions on line 56 and 67 from == 39 to == 5 (and fix line 30 and 51; see comments) to:

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <math.h>


using namespace std;

float plot(float x);

float plot(float x)
{
  float y;

  y=sin(x);

  return y;
}

int main(int argc, char *argv[])
{

  int point[80][24];
  int j;
  float k,Pi;


  Pi=3.14159265358;

  for(int a=0;a<=23;a++) // was 24
  {
    for(int b=0;b<=79;b++)
    {
      point[b][a]=0;
    }
  }


  for(float i=-480;i<480;i++)
  {
    int z=int((i+480)/12);

    k = 12 + 4 *  -plot((i * Pi)/180);
    j=int(k);

    if (j <= 24 & j >0)
      point[z][j]=1;
  }


  for(int y=1;y<=23;y++) // was 24
  {
    if (y == 12)
      for(int d=0;d<=79;d++)
        if (point[d][12] == 0)
          if (d==5) // was 39
            cout << char(197);
          else
            cout << char(196);
          else
           cout << "o";
        else
        {
          for(int x=0;x<=79;x++)
          {
            if (point[x][y] == 0)
              if (x==5) // was 39
                cout << char(179);
              else
                cout << " ";
            else
                cout << "o";
          }
      }
  }
  return 0;
}
Last edited on
ok thanks but theres still some of the wave on the left. i want the wave to start where the two axis's intersect
hello?
The base way to learn is to experiment!

1
2
3
          for(int x=5;x<=79;x++) // e.g. start later!
          {
              ...


What would help is if you replace the limits of your ranges with constants

e.g.

1
2
3
4
5
6
7
8
9
10
...

const int x_min =  5;
const int x_max = 79;

...

          for(int x=x_min;x<=x_max;x++)
          {
              ...


then you can try adusting the min/max/etc by changing values in one place, rather than many!

Andy

P.S. My ISP has not been so happy over the last couple of days...
Last edited on
Magic Numbers
http://en.wikipedia.org/wiki/Magic_number_%28programming%29

See the third definition.

You could also use

1
2
3
const char horz_line = char(179);
const char point = 'o';
...
Last edited on
Topic archived. No new replies allowed.