Reflection of triangle|computer graphics|

 Reflection triangle in 2D transformation


code

#include <conio.h>
#include <graphics.h>
#include <stdio.h>
  
// Driver Code
void main()
{
    int gm, gd = DETECT, a,x1,y1,x2,y2,x3,y3;
    initgraph(&gd, &gm, "c:\\turboc3\\bgi");
    cleardevice();
  
    // Draw the graph
    line(getmaxx() / 2, 0, getmaxx() / 2,
         getmaxy());
    line(0, getmaxy() / 2, getmaxx(),
getmaxy() / 2);
printf("Enter x1 and y1:\n");
scanf("%d%d",&x1,&y1);
printf("Enter x2 and y2");
scanf("%d%d",&x2,&y2);
printf("Enter x3 and y3\n");
scanf("%d%d",&x3,&y3);
    setcolor(14);
    line(x1, y1, x2, y2);
    line(x2, y2, x3, y3);
    line(x3, y3, x1, y1);///
    getch();
printf("Enter 1 for x and 2 for y:\n");
scanf("%d",&a);
switch(a){
case 1:
    setcolor(3);
    line(getmaxx() - x1, y1,
getmaxx() - x2, y2);
    line(getmaxx() - x2, y2,
getmaxx() - x3, y3);
    line(getmaxx() - x3, y3,
getmaxx() - x1, y1);
  break;
case 2:
    setcolor(2);
    line(x1, getmaxy() - y1, x2,
         getmaxy() - y2);
    line(x2, getmaxy() - y2, x3,
         getmaxy() - y3);
    line(x3, getmaxy() - y3, x1,
         getmaxy() - y1);
    getch();
  break;
default:
printf("Enter valid direction\n");
}
delay(2000);
    closegraph();
}


output:



Comments

Popular posts from this blog

Use of Backslash "\n" in C language

COHESION AND COUPLING material

Coding and Testing in software engineering