Advertisement
RuslanMag

graph

May 17th, 2020
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <math.h>
  2. #include <graphics.h>
  3.  
  4. const int WIDTH = getmaxwidth(), HEIGHT = getmaxheight();
  5.  
  6. void drawLine(int moveToX, int moveToY, int drawX, int drawY, int color, int textX, int textY, char *name)
  7. {
  8.     moveto(moveToX, moveToY);
  9.     setcolor(color);
  10.     lineto(drawX, drawY);
  11.     outtextxy(textX, textY, name);
  12. }
  13.  
  14. int main()
  15. {
  16.     double x, y;
  17.     float xMin, xMax;
  18.    
  19.     printf("y = sin(x)\n");
  20.    
  21.     printf("Enter Xmin = ");
  22.     scanf("%f", &xMin);
  23.     printf("Enter Xmax = ");
  24.     scanf("%f", &xMax);
  25.    
  26.     printf("Width = %d\t Height = %.d\n", WIDTH, HEIGHT);
  27.    
  28.     delay(1000);
  29.    
  30.     initwindow(WIDTH, HEIGHT);
  31.     moveto(WIDTH / 2, HEIGHT / 2);
  32.    
  33.     drawLine(0, HEIGHT / 2, WIDTH, HEIGHT / 2, WHITE, WIDTH - 20, HEIGHT / 2 + 20, "X");
  34.     drawLine(WIDTH / 2, 0, WIDTH / 2, HEIGHT, WHITE, WIDTH/2 + 20, 0 , "Y");
  35.     line(WIDTH/2, 0, WIDTH/2 + 10, 20);
  36.     line(WIDTH/2, 0, WIDTH/2 - 10, 20);
  37.    
  38.     line(WIDTH, HEIGHT/2, WIDTH-20, HEIGHT/2 - 10);
  39.     line(WIDTH, HEIGHT/2, WIDTH-20, HEIGHT/2 + 10);
  40.    
  41.     for(x = xMin; x < xMax; x += 0.01)
  42.     {
  43.         y = -sin(x);
  44.         setcolor(14);
  45.         putpixel(WIDTH / 2 + (x * 50), HEIGHT / 2 + (y * 50), 2);
  46.     }
  47.    
  48.     getch();
  49.     closegraph();
  50.     system("PAUSE");
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement