Posts

Showing posts from December, 2020

C++ PROGRAM TO IMPLEMENT THE CONCEPT OF REFLEXION

Image
C++ PROGRAM TO IMPLEMENT THE CONCEPT OF REFLEXION CODE: #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> void show(float a[][3]){ float xm,ym; int i=0; xm=getmaxx()/2; ym=getmaxy()/2; while(i<2){ line(xm+a[i][0],ym-a[i][1],xm+a[i+1][0],ym-a[i+1][1]); i++; } i=2; line(xm+a[i][0],ym-a[i][1],xm+a[0][0],ym-a[0][1]); setcolor(RED); line(0,ym,xm*2,ym); line(xm,0,xm,ym*2); setcolor(BLUE); } void matmul(float b[][3],float a[][3],float c[][3]){ int i,j,m; for(i=0;i<3;i++){ for(j=0;j<3;j++){ c[i][j]=0; } } for(i=0;i<3;i++){ for(j=0;j<3;j++){ for(m=0;m<3;m++){ c[i][j]=c[i][j]+(a[i][m]*b[m][j]); } } } } void ref(float a[][3]){ float b[10][3],c[10][3]; int i=0,j; show(a); for(i=0;i<3;i++){ for(j=0;j<3;j++){ b[i][j]=0; if(i==j) b[i][j]=1; } } b[1][1]=-1; matmul(b,a,c); setcolor(YELLOW); show(c); } int main(){ int gdriver=DETECT,gmode; float a[10][3]; initgrap...

C++ PROGRAM TO IMPLEMENT THE CONCEPT OF TRANSLATION

Image
C++ PROGRAM TO IMPLEMENT THE CONCEPT OF TRANSLATION CODE: #include<stdio.h> #include<graphics.h> #include<conio.h> int main() {     int gd=DETECT,gm;     int x,y,x1,y1,x2,y2,tx,ty;     initgraph(&gd,&gm,"C:\\WINDOWS\\BGI");     printf("\n Enter the first coordinates of the triangle: ");     scanf("%d %d",&x,&y);     printf("\n Enter the second coordinates of the traingle: ");     scanf("%d %d",&x1,&y1);     printf("\n Enter the third coordinates of the traingle: ");     scanf("%d %d",&x2,&y2);     printf("\n\t\t************TRIANGLE BEFORE AND AFTER TRANSLATION*************");     line(x,y,x1,y1);     line(x1,y1,x2,y2);     line(x2,y2,x,y);     outtextxy(x1,y1+5,"BEFORE TRANSLATION");     printf("\n Now enter the translation vector: ");     scanf("%d %d",&tx,&ty);   ...

C++ PROGRAM TO IMPLEMENT THE CONCEPT OF FIXED SCALING

Image
C++ PROGRAM TO IMPLEMENT THE CONCEPT OF FIXED SCALING CODE: #include<stdio.h> #include<graphics.h> #include<conio.h> int main() {     int gd=DETECT,gm;     int x=100,y=100,x1=200,y1=200,x2=300,y2=100,sx=2,sy=1,tx=100,ty=200;     initgraph(&gd,&gm,"");     setcolor(YELLOW);     line(x,y,x1,y1);     line(x1,y1,x2,y2);     line(x2,y2,x,y);     outtextxy(140,210,"BEFORE SCALING");     setcolor(CYAN);     line(x*sx+tx*(1-sx),y*sy+ty*(1-sy),x1*sx+tx*(1-sx),y1*sy+ty*(1-sy));     line(x1*sx+tx*(1-sx),y1*sy+ty*(1-sy),x2*sx+tx*(1-sx),y2*sy+ty*(1-sy));     line(x2*sx+tx*(1-sx),y2*sy+ty*(1-sy),x*sx+tx*(1-sx),y*sy+ty*(1-sy));     outtextxy(340,210,"AFTER SCALING");     getch();     closegraph();     return 0; } OUTPUT:

C++ PROGRAM TO IMPLEMENT THE CONCEPT OF FREE SCALING

Image
  C++ PROGRAM TO IMPLEMENT THE CONCEPT OF FREE SCALING CODE: #include<stdio.h> #include<graphics.h> #include<conio.h> int main() {     int gd=DETECT,gm;     int x=100,y=100,x1=200,y1=200,x2=300,y2=100,sx=2,sy=1;     initgraph(&gd,&gm,"");     setcolor(YELLOW);     line(x,y,x1,y1);     line(x1,y1,x2,y2);     line(x2,y2,x,y);     outtextxy(140,210,"BEFORE SCALING");     setcolor(CYAN);     line(x*sx,y*sy,x1*sx,y1*sy);     line(x1*sx,y1*sy,x2*sx,y2*sy);     line(x2*sx,y2*sy,x*sx,y*sy);     outtextxy(340,210,"AFTER SCALING");     getch();     closegraph();     return 0; } OUTPUT:

C++ PROGRAM TO IMPLEMENT THE CONCEPT OF 8 WAY BOUNDARY FILLING ALGORITHM

Image
C++ PROGRAM TO IMPLEMENT THE CONCEPT OF 8 WAY BOUNDARY FILLING ALGORITHM CODE: #include<stdio.h> #include <graphics.h> void boundaryFill8(int x, int y, int fill_color,int boundary_color) {     if(getpixel(x, y) != boundary_color &&        getpixel(x, y) != fill_color)     {         putpixel(x, y, fill_color);         boundaryFill8(x + 1, y, fill_color, boundary_color);         boundaryFill8(x, y + 1, fill_color, boundary_color);         boundaryFill8(x - 1, y, fill_color, boundary_color);         boundaryFill8(x, y - 1, fill_color, boundary_color);         boundaryFill8(x - 1, y - 1, fill_color, boundary_color);         boundaryFill8(x - 1, y + 1, fill_color, boundary_color);         boundaryFill8(x + 1, y - 1, fill_color, boundary_color);         bou...

C++ PROGRAM TO IMPLEMENT THE CONCEPT OF 4 WAY BOUNDARY FILLING ALGORITHM

Image
 C++ PROGRAM TO IMPLEMENT THE CONCEPT OF 4 WAY BOUNDARY FILLING ALGORITHM CODE: // C Implementation for 4 way Boundary Filling Algorithm #include<graphics.h> #include<stdlib.h> #include<iostream> #include<conio.h> int main() { void boundary_fill(int x,int y,int f,int b); int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "C:\\TC\\BGI"); setcolor(getmaxcolor()); int points[]={50,50,50,100,100,150,150,100,200,200,250,100,250,50,50,50}; drawpoly(8, points); boundary_fill(100,100,4,15); getch(); closegraph(); return 0; } void boundary_fill(int x,int y,int f,int b) { if(getpixel(x,y)!=b && getpixel(x,y)!=f) { putpixel(x,y,f); boundary_fill(x+1,y,f,b); boundary_fill(x-1,y,f,b); boundary_fill(x,y+1,f,b); boundary_fill(x,y-1,f,b); } } OUTPUT:

C++ PROGRAM TO IMPLEMEMT THE CONCEPT OF FLOODFILL ALGORITHM

Image
 C++ PROGRAM TO IMPLEMEMT THE CONCEPT OF FLOODFILL ALGORITHM CODE: // program to fill a polygon using floodfill algorithm #include <graphics.h> #include <stdio.h> void flood(int x, int y, int new_col, int old_col) {     if (getpixel(x, y) == old_col) {         putpixel(x, y, new_col);         flood(x + 1, y, new_col, old_col);         flood(x - 1, y, new_col, old_col);         flood(x, y + 1, new_col, old_col);         flood(x, y - 1, new_col, old_col);     } } int main() {     int gd, gm = DETECT;     initgraph(&gd, &gm, "");     int top, left, bottom, right;     top = left = 50;     bottom = right = 300;     int points[]={50,50,50,100,100,150,150,100,200,200,250,100,250,50,50,50}; drawpoly(8, points);     int x = 51;     int y = 51;     int newcolor = ...

C++ CODE TO IMPLEMENT AN ELLIPSE USING COMPUTER GRAPHICS

Image
 C++ CODE TO IMPLEMENT AN ELLIPSE USING COMPUTER GRAPHICS CODE: #include<stdio.h> #include<graphics.h> int main() {    int gd = DETECT, gm;    int xc,yc,x,y;float p;    long rx,ry;    initgraph(&gd, &gm, "C:\\TC\\BGI");    printf("Enter coordinates of centre : ");    scanf("%d%d",&xc,&yc);    printf("Enter x,y radius of ellipse: ");    scanf("%d%d",&rx,&ry);    //Calculating points for the Region 1    p=ry*ry-rx*rx*ry+rx*rx/4;    x=0;y=ry;    while(2.0*ry*ry*x <= 2.0*rx*rx*y)    { if(p < 0) { x++; p = p+2*ry*ry*x+ry*ry; } else { x++;y--; p = p+2*ry*ry*x-2*rx*rx*y-ry*ry; } putpixel(xc+x,yc+y,15); putpixel(xc+x,yc-y,15); putpixel(xc-x,yc+y,15); putpixel(xc-x,yc-y,15);    }   //Calculating points for the Region 2    p=ry*ry*(x+0.5)*(x+0.5)+rx*rx*(y-1)*(y-1)-rx...

IMPLEMENTATION OF DDA LINE DRAWING ALGORITHM USING C++

Image
  IMPLEMENTATION OF DDA LINE DRAWING ALGORITHM USING C++  : CODE: #include<stdio.h> #include<conio.h> #include<graphics.h> main() { //INITIALIZING THE STARTING AND ENDING POINT int x1=100,y1=100,x2=500,y2=400,dx,dy,length,i; float x,y,xinc,yinc; int gd=DETECT,gm; initgraph(&gd,&gm,"c:\\tc\\bgi"); //CALCULATING DY AND DX dx=x2-x1; dy=y2-y1; //CONDITIONS FOR CALCULATING LENGTH if(abs(dx)>abs(dy))     length=abs(dx); else     length=abs(dy); //CALCULATION X AND Y VALUES FOR ITERATIONS xinc=dx/(float)length; yinc=dy/(float)length; x=x1; y=y1; floodfill(3,5,WHITE); putpixel(x,y,0); for(i=0;i<length;i++) {     putpixel(x,y,0);     x=x+xinc;     y=y+yinc;     delay(10); } getch(); closegraph(); } OUTPUT: