Write a program to scale a figure given by user. Options for the users are circle, triangle or rectangle.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>

void Triangle(int, int, int, int, int, int);
//int midx=319, midy=239;

void  main()
{
  int gdriver=DETECT, gmode, c,r,x1,y1,x2,y2,x3,y3;
  float S,Sx,Sy;
  initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

  clrscr();
  cleardevice();

  printf("1.Circle \n2.Triangle \n3.Rectangle \n\n");
  printf("Enter the choice : ");
  scanf("%d",&c);
  clrscr();
  cleardevice();

  switch(c)
  {
        case 1:
              printf("Enter the value of center (x1,y1) : ");
              scanf("%d %d",&x1,&y1);
              printf("Enter the Radius of the circle r : ");
              scanf("%d",&r);
              printf("Enter the scaling Factor S : ");
              scanf("%f",&S);
              circle(x1,y1,r);
              //    line(0,midy,2*midx,midy);
              //    line(midx,0,midx,2*midy);
              getch();    setcolor(4);
              circle(x1,y1,r*S);
              break;

        case 2:
              printf("Enter the value of (x1,y1) : ");
              scanf("%d %d",&x1,&y1);
              printf("Enter the value of (x2,y2) : ");
              scanf("%d %d",&x2,&y2);
              printf("Enter the value of (x3,y3) : ");
              scanf("%d %d",&x3,&y3);
              printf("Enter the scaling Factor (Sx,Sy) : ");
              scanf("%f %f",&Sx,&Sy);
              //    line(0,midy,2*midx,midy);
              //    line(midx,0,midx,2*midy);
              Triangle(x1,y1,x2,y2,x3,y3);
              getch();    setcolor(4);
              Triangle(x1*Sx,y1*Sy,x2*Sx,y2*Sy,x3*Sx,y3*Sy);
              break;

  case 3:
        printf("Enter the top-left point of the rectangle : ");
        scanf("%d %d",&x1,&y1);
  printf("\n\nEnter the bottom-right point of the rectangle : ");
              scanf("%d %d",&x2,&y2);
              printf("Enter the scaling Factor (Sx,Sy) : ");
              scanf("%f %f",&Sx,&Sy);
             //     line(0,midy,2*midx,midy);
            //      line(midx,0,midx,2*midy);
              rectangle(x1,y1,x2,y2);
              getch();    setcolor(4);
              rectangle(x1*Sx,y1*Sy,x2*Sx,y2*Sy);
              break;
  }
  getch();
  closegraph();
}

void Triangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
  line(x1,y1,x2,y2);
  line(x2,y2,y3,y3);
  line(x3,y3,x1,y1);
}

Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP