Computer Graphic Lab Report Sample

 

<logo>

 

<College Name>

<Address>

Affiliated under TU

2080

Lab report on

<Subject>

 

 

 

 

 

 

 

 


Prepared By:

<Name>

Stream: Faculty of Humanities and Social Science

Registration No.:……………..

 

Prepared For:

 

 

--------------------------                                                                     ---------------------

Name: ………………..

(Internal Examiner)                                                                      (External Examiner)             

 


DECLARATION

I hereby declare that the work presented in this project report has done by myself under the supervision <name> and has not been submitted elsewhere for any examination. All sources of information have been specifically acknowledged by references to authors or institutions.

 

 

 

 

 

 

 

 

 

 

 

Date: ______________                                                          Name: __________

                                                                                                Reg No. :             

 

 

 

 

 

 

 

 

 

 

 

 

LETTER OF APPROVAL

 

The project work submitted to <college name>, by<name>, entitled “<subject>” has been approved as the partial fulfillment of the requirements of the internal evaluation.

 

 

 

 

 

 

 

 

 

 

____________________

Name & Signature of Supervisor

Date: _____________                                           

 

 

 

 

 

 

 

 

 

 

ACKNOWLEDGEMENT

Under the prescribed syllabus by TU, BCA students are required to prepare their project work, showing their skills and knowledge in the field. It’s my great pleasure to have been able to show my innate confidence in practical as well as theoretical knowledge. I would like to extend my sincere thanks and gratitude to my teacher <name of teacher> for his valuable suggestions and inspiration that assisted me in preparing my work. The credit also goes to all my colleagues for helping me bring my project work to existence.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TABLE OF CONTENT

LAB 1. 1

1.1      Introduction. 1

1.2      Application of Computer Graphic. 1

1.3      Program to implement DDA Line Drawing Algorithm. 2

LAB 2. 4

2.1      Program to Implement Brenham's Line drawing Algorithm.(For |m|<1 and |m|>1). 4

LAB 3. 6

3.1      Program to implement Mid -Point Circle Algorithm.(For Clockwise and Anticlockwise Movement). 6

3.1.1       For Anticlockwise: 6

3.1.2       For Clockwise. 7

LAB 4. 8

4.1      Program to implement Mid-Point Ellipse Algorithm. 8

LAB 5. 10

5.1      Program to implement 2D-Transformation-Translation, Rotation, Scaling. 10

5.1.1       For Translation. 10

5.1.2       For Rotation. 11

5.1.3       For Scaling. 12

LAB 6. 13

6.1      Program to implement 2D-Transformation-Reflection, Shear. 13

6.1.1       For Reflection. 13

6.1.2       For Shear 15

LAB 7. 16

7.1      Program to implement Cohen Sutherland Line Clipping Algorithm. 16

LAB 8. 20

8.1      Program to implement 3D-Transformation- Translation, Rotation and Scaling (including Hidden Surface Removal Algorithm). 20

8.1.1       For Translation. 20

8.1.2       For Scaling. 21

8.1.3       For Rotation. 22

LAB 9. 25

9.1      Program to implement of flood fill and boundary fill algorithm. 25

9.1.1       For flood fill algorithm.. 25

9.1.2       For boundary fill algorithm.. 27

CONLUSION.. 29

REFERENCES. 30


LAB 1

 

1.1       Introduction

 

Computer Graphics is a field related to the generation of graphics using computers. Computer graphics are graphics created using computers and the representation of image data by a computer specifically with help from specialized graphic hardware and software.

It includes the creation, storage, and manipulation of images of objects. These objects come from diverse fields such as physical, mathematical, engineering, architectural, abstract structures and natural phenomenon. Computer Graphics today is largely interactive, that is, user controls the contents, structure and appearance of images by using different input devices, such as keyboard, mouse, light pen or touch panels on the screen.

 

1.2       Application of Computer Graphic

 

1.      Computer Aided Design (CAD)

2.      Presentation Graphics

3.      Computer Art

4.      Entertainment

5.      Education and Training

6.      Visualization

7.      Image Processing

8.      Graphical User Interfaces (GUI‟s)

9.      Simulation

10.  Cartography

 


1.3      Program to implement DDA Line Drawing Algorithm.

 

#include<graphics.h> 

#include<stdio.h> 


main() 

{ 

    int gd = DETECT ,gm, i; 

    float x, y,dx,dy,steps; 

    int x0, x1, y0, y1; 

    initgraph(&gd, &gm, "C:\\TC\\BGI"); 

    setbkcolor(WHITE); 

    x0 = 100 , y0 = 200, x1 = 500, y1 = 300; 

    dx = (float)(x1 - x0); 

    dy = (float)(y1 - y0); 

    if(dx>=dy) 

           { 

        steps = dx; 

    } 

    else 

           { 

        steps = dy; 

    } 

    dx = dx/steps; 

    dy = dy/steps; 

    x = x0; 

    y = y0; 

    i = 1; 

    while(i<= steps) 

    { 

        putpixel(x, y, RED); 

        x += dx; 

        y += dy; 

        i=i+1; 

    } 

            getch();

    closegraph();

               

} 

 

LAB 2

2.1       Program to Implement Bresenham's Line drawing Algorithm.(For |m|<1 and |m|>1).

 

#include <stdio.h>

#include <graphics.h>

#include <stdlib.h>

#include <dos.h>

#include <conio.h>

 

void drawLine(int x0, int y0, int x1, int y1) {

 

    int dx = x1 - x0;

    int dy = y1 - y0;

    int x = x0;

    int y = y0;

    int x_inc = 1, y_inc = 1;

    int steps;

 

    if (abs(dx) > abs(dy)) {

            steps = abs(dx);

    } else {

            steps = abs(dy);

    }

 

    if (dx < 0) {

            x_inc = -1;

            dx = -dx;

    }

    if (dy < 0) {

            y_inc = -1;

            dy = -dy;

    }

 

    putpixel(x, y, WHITE);

 

    if (abs(dx) > abs(dy)) {

            int p = 2 * abs(dy) - abs(dx);

            for (int i = 0; i < steps; ++i) {

                if (p >= 0) {

                        y += y_inc;

                        p -= 2 * abs(dx);

                }

                x += x_inc;

                p += 2 * abs(dy);

                putpixel(x, y, WHITE);

            }

    } else {

            int p = 2 * abs(dx) - abs(dy);

            for (int i = 0; i < steps; ++i) {

                if (p >= 0) {

                        x += x_inc;

                        p -= 2 * abs(dy);

                }

                y += y_inc;

                p += 2 * abs(dx);

                putpixel(x, y, WHITE);

            }

    }

}

void main() {

    int gd = DETECT, gm;

    initgraph(&gd, &gm, "C:\\TC\\BGI");

    int x0, y0, x1, y1;

    printf("Enter coordinates of first point (x0 y0): ");

    scanf("%d %d", &x0, &y0);

    printf("Enter coordinates of second point (x1 y1): ");

    scanf("%d %d", &x1, &y1);

    drawLine(x0, y0, x1, y1);

    getch();

    closegraph();

}

 


LAB 3

 

3.1       Program to implement Mid -Point Circle Algorithm.(For Clockwise and Anticlockwise Movement).

 

3.1.1        For Anticlockwise:

 

#include <stdio.h>

#include <graphics.h>

#include <conio.h>

 

void drawCircle(int xc, int yc, int x, int y) {

    putpixel(xc+x, yc-y, WHITE);

    putpixel(xc+y, yc-x, WHITE);

    putpixel(xc-x, yc-y, WHITE);

    putpixel(xc-y, yc-x, WHITE);

}

void midpointCircle(int xc, int yc, int r) {


    int x = 0, y = r;

    int d = 1 - r;

    drawCircle(xc, yc, x, y);

    while (y > x) {

            if (d < 0) {

                d += 2*x + 3;

                x++;

            }

            else {

                d += 2*(x-y) + 5;

                x++;

                y--;

            }

            drawCircle(xc, yc, x, y);

    }

}

void main() {

    int gd = DETECT, gm;

    initgraph(&gd, &gm, "C:\\TC\\BGI");

    int xc = 250, yc = 250, r = 100;

    midpointCircle(xc, yc, r);

    getch();

    closegraph();

}

 

3.1.2        For Clockwise

 

#include <stdio.h>

#include <graphics.h>

#include <conio.h>

void drawCircle(int xc, int yc, int x, int y) {

    putpixel(xc+x, yc+y, WHITE);

    putpixel(xc+y, yc+x, WHITE);

    putpixel(xc-x, yc+y, WHITE);

    putpixel(xc-y, yc+x, WHITE);


}

void midpointCircle(int xc, int yc, int r) {

    int x = 0, y = r;

    int d = 1 - r;

 

    drawCircle(xc, yc, x, y);

 

    while (y > x) {

            if (d < 0) {

                d += 2*x + 3;

                x++;

            }

            else {

                d += 2*(x-y) + 5;

                x++;

                y--;

            }

            drawCircle(xc, yc, x, y);

    }

}

 

int main() {

    int gd = DETECT, gm;

    initgraph(&gd, &gm, "C:\\TC\\BGI");

 

    int xc = 250, yc = 250, r = 100;

    midpointCircle(xc, yc, r);

    getch();

    closegraph();

    return 0;

}


LAB 4

 

4.1       Program to implement Mid-Point Ellipse Algorithm.

 

#include<graphics.h>

#include<conio.h>

#include<stdio.h>

void plotpoints(int cx, int cy, int x, int y) {

            putpixel(cx + x, cy + y, 4);

            putpixel(cx - x, cy + y, 4);

            putpixel(cx + x, cy - y, 4);

            putpixel(cx - x, cy - y, 4);

}

void main() {

 

            int cx, cy, rx, ry;

            printf("Enter the center ");

            scanf("%d%d", &cx, &cy);

            printf("x radius : ");

            scanf("%d", &rx);

            printf("y radius : ");

            scanf("%d", &ry);

            long rx2 = (long) rx * rx;

            long ry2 = (long) ry * ry;

            long trx2 = 2 * rx2;

            long try2 = 2 * ry2;

            long p, x = 0, y = ry;

            long px = 0;

            long py = trx2 * y;

            p = (long) ((ry2 - (rx2 * ry) + (0.25 * rx2)) + 0.5);

            int gd = DETECT, gm = DETECT;

            initgraph(&gd, &gm, "C:\\TC\\BGI");

            cleardevice();

            putpixel(cx, cy, 15);

            while (px < py) {

                        plotpoints(cx, cy, x, y);

                        x++;

                        px += try2;

                        if (p < 0)

                                        p += ry2 + px; else {

                                    y--;

                                    py -= trx2;

                                    p += ry2 + px - py;

                        }

            }

            py = trx2 * y;

            px = try2 * x;

            p = (long) ((ry2 * (x + 0.5) * (x + 0.5) + rx2 * (y - 1) * (y - 1) - rx2 * ry2) + 0.5);

            while (y >= 0) {

                        plotpoints(cx, cy, x, y);

                        y--;

                        py -= trx2;

                        if (p > 0)

                                        p += rx2 - py; else {

                                    x++;

                                    px += try2;

                                    p += rx2 - py + px;

                        }

            }

            getch();

            closegraph();

}

 


LAB 5

 

5.1       Program to implement 2D-Transformation-Translation, Rotation, Scaling.

5.1.1        For Translation

 

#include<graphics.h>

#include<stdlib.h>

#include<stdio.h>

#include<math.h>

#include<conio.h>

void main()

{

int graphdriver=DETECT,graphmode,errorcode;

int i;

int x2,y2,x1,y1,x,y;

mprintf("Enter the 2 line end points:");

printf("x1,y1,x2,y2");

scanf("%d%d%d%d",&x1,&y1,&x2,&y2);

initgraph(&graphdriver,&graphmode,"c:\\tc\\bgi");

line(x1,y1,x2,y2);

printf("Enter translation co-ordinates ");

printf("x,y");


scanf("%d%d",&x,&y);

x1=x1+x;

y1=y1+y;

x2=x2+x;

y2=y2+y;

printf("Line after translation");

line(x1,y1,x2,y2);

getch();

closegraph();

}


5.1.2        For Rotation

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

void main()

{

int gd=DETECT,gm;

float x1,y1,x2,y2,x3,y3,x4,y4,a,t;

initgraph(&gd,&gm, "C:\\TC\\BGI");

printf("\nEnter coordinates of starting point(x1,y1): ");

scanf("%f%f",&x1,&y1);

printf("\nEnter coordinates of ending point(x2,y2): ");

scanf("%f",&a);

setcolor(7);

printf("\nEnter angle for rotation (degree): ");

scanf("%f%f",&x2,y2);

line(x1,y1,x2,y2);

outtextxy(x2+5,y2, "Object");

t=a*(3.14/180);

x3=(x1*cos(t))-(y1*sin(t));

y3=(x1*sin(t))+(y1*cos(t));

x4=(x2*cos(t))-(y2*sin(t));

y4=(x2*sin(t))+(y2*cos(t));

setcolor(15);

line(x3,y3,x4,y4);

outtextxy(x3+10,y3, "Image");

getch();

}


5.1.3        For Scaling

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

void main()

{

int gd=DETECT,gm;

float x1,y1,x2,y2,sx,sy,x3,y3,x4,y4;

initgraph(&gd,&gm, "C:\\TC\\BGI");

printf("\nEnter the starting point coordinates(x1,y1): ");

scanf("%f %f",&x1,&y1);

printf("\nEnter the ending point coordinates(x2,y2): ");

scanf("%f %f",&x2, y2);

printf("\nEnter scaling factors(sx,sy): ");

scanf("%f%f",&sx,&sy);

setcolor(7);

line(x1,y1,x2,y2);

outtextxy(x2+5,y2,"Object");

x3=x1*sx;

y3=y1*sy;

x4=x2*sx;

y4=y2*sy;

setcolor(15);

line(x3,y3,x4,y4);

outtextxy(x4+5,y4,"Image");

getch();


}


 


LAB 6

 

6.1       Program to implement 2D-Transformation-Reflection, Shear.

 

6.1.1        For Reflection

#include <stdio.h>

#include <conio.h>

#include <graphics.h>

#include <math.h>

char IncFlag;

int PolygonPoints[3][2] = {{10,100},{110,100},{110,200}};

void PolyLine()

{

int iCnt;

cleardevice();

line(0,240,640,240);

line(320,0,320,480);

for (iCnt=0; iCnt<3; iCnt++)

{

            line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],

            PolygonPoints[(iCnt+1)%3][0],PolygonPoints[(iCnt+1)%3][1]);

}

}

void Reflect()

{

float Angle;

int iCnt;

int Tx, Ty;

printf("endl");

for (iCnt=0;iCnt<3;iCnt++)

            PolygonPoints[iCnt][1]=(480-PolygonPoints[iCnt][1]);

}

void main()

{

int gd= DETECT, gm;

int iCnt;

initgraph(&gd, &gm, "C:\\TC\\BGI");

for (iCnt=0; iCnt<3;iCnt++)

{

            PolygonPoints[iCnt][0] += 320;

            PolygonPoints[iCnt][1] = 240-PolygonPoints[iCnt][1];

}

PolyLine();

getch();

Reflect();

PolyLine();

getch();

}


6.1.2        For Shear

 

#include<stdio.h>

#include<conio.h>

#include<dos.h>

#include<graphics.h>

void main()

{

int gd=DETECT,gm;

float shx,shy;

initgraph(&gd,&gm,"C:\\TC\\BGI");

printf("Enter shear factor shy along y-axis:");

scanf("%f", &shy);

line(100,10,200,10);

line(200,10,200,200);

line(200,200,100,200);

line(100,200,100,10);

printf("Y-shear");

setcolor(12);

line(100,10+(shy*100),200,10+(shy*200));

line(200,10+(shy*200),200,200+(shy*200));

line(200,200+(shy*200),100,200+(shy*100));

line(100,200+(shy*100),100,10+(shy*100));

getch();

closegraph();

}

 

                                                        

LAB 7

 

7.1       Program to implement Cohen Sutherland Line Clipping Algorithm.

 

#include<graphics.h>

#include<conio.h>

#include<stdio.h>

#include<math.h>

#include<stdlib.h>

#include<dos.h>

void main()

{

int rcode_begin[4]={0,0,0,0},rcode_end[4]={0,0,0,0},region_code[4];

int W_xmax,W_ymax,W_xmin,W_ymin,flag=0;

float slope;

int x,y,x1,y1,i, xc,yc;

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\TC\\BGI");

printf("\n****** Cohen Sutherlsnd Line Clipping algorithm ***********");

printf("\n Now, enter XMin, YMin =");

scanf("%d %d",&W_xmin,&W_ymin);

printf("\n First enter XMax, YMax =");

scanf("%d %d",&W_xmax,&W_ymax);

printf("\n Please enter intial point x and y= ");

scanf("%d %d",&x,&y);

printf("\n Now, enter final point x1 and y1= ");

scanf("%d %d",&x1,&y1);

cleardevice();

rectangle(W_xmin,W_ymin,W_xmax,W_ymax);

line(x,y,x1,y1);

line(0,0,600,0);

line(0,0,0,600);

if(y>W_ymax)  {

rcode_begin[0]=1;     // Top

flag=1 ;

}

if(y<W_ymin) {

rcode_begin[1]=1;           // Bottom

flag=1;

}

if(x>W_xmax)  {

rcode_begin[2]=1;           // Right

flag=1;

}

if(x<W_xmin)   {

rcode_begin[3]=1;           //Left

flag=1;

}

//end point of Line

if(y1>W_ymax){

rcode_end[0]=1;           // Top

flag=1;

}

if(y1<W_ymin) {

rcode_end[1]=1;           // Bottom

flag=1;

}

if(x1>W_xmax){

rcode_end[2]=1;           // Right

flag=1;

}

if(x1<W_xmin){

rcode_end[3]=1;           //Left

flag=1;

 }

if(flag==0)

{

printf("No need of clipping as it is already in window");

}

flag=1;

for(i=0;i<4;i++){

region_code[i]= rcode_begin[i] && rcode_end[i] ;

if(region_code[i]==1)

 flag=0;

}

if(flag==0)

{

printf("\n Line is completely outside the window");

}

else{

slope=(float)(y1-y)/(x1-x);

if(rcode_begin[2]==0 && rcode_begin[3]==1)   //left

{

y=y+(float) (W_xmin-x)*slope ;

x=W_xmin;

 

}

if(rcode_begin[2]==1 && rcode_begin[3]==0)       // right

{

y=y+(float) (W_xmax-x)*slope ;

x=W_xmax;

 

}

if(rcode_begin[0]==1 && rcode_begin[1]==0)      // top

{

x=x+(float) (W_ymax-y)/slope ;

y=W_ymax;

 

}

if(rcode_begin[0]==0 && rcode_begin[1]==1)     // bottom

{

x=x+(float) (W_ymin-y)/slope ;

y=W_ymin;

 

}

// end points

if(rcode_end[2]==0 && rcode_end[3]==1)   //left

{

y1=y1+(float) (W_xmin-x1)*slope ;

x1=W_xmin;

 

}

if(rcode_end[2]==1 && rcode_end[3]==0)       // right

{

y1=y1+(float) (W_xmax-x1)*slope ;

x1=W_xmax;

 

}

if(rcode_end[0]==1 && rcode_end[1]==0)      // top

{

x1=x1+(float) (W_ymax-y1)/slope ;

y1=W_ymax;

 

}

if(rcode_end[0]==0 && rcode_end[1]==1)     // bottom

{

x1=x1+(float) (W_ymin-y1)/slope ;

y1=W_ymin;

 

}

}

delay(1000);

clearviewport();

rectangle(W_xmin,W_ymin,W_xmax,W_ymax);

line(0,0,600,0);

line(0,0,0,600);

setcolor(RED);

line(x,y,x1,y1);

getch();

closegraph();

}

 


LAB 8

 

8.1       Program to implement 3D-Transformation- Translation, Rotation and Scaling (including Hidden Surface Removal Algorithm).

 

8.1.1        For Translation


#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

int maxx,maxy,midx,midy;

void axis()

{

getch();

cleardevice();

line(midx,0,midx,maxy);

line(0,midy,maxx,midy);

}

void main()

{

int x,y,z,o,x1,x2,y1,y2;

int gd=DETECT,gm;

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\tc\\bgi");

maxx=getmaxx();

maxy=getmaxy();

midx=maxx/2;

midy=maxy/2;

axis();

bar3d(midx+50,midy-100,midx+60,midy-90,10,1);

outtextxy(midx+30,midy-80,"Object");

printf("Enter translation factor");

scanf("%d%d",&x,&y);

printf("After translation:");

bar3d(midx+x+50,midy-(y+100),midx+x+60,midy-(y+90),10,1);

outtextxy(midx+x+70, midy-(y+120),"Image");

getch();

closegraph();

}

 

 

 

 

8.1.2        For Scaling

 

#include<stdio.h>                          

#include<conio.h>

#include<graphics.h>

#include<math.h>

int maxx,maxy,midx,midy;

void axis()

{

getch();

cleardevice();

line(midx,0,midx,maxy);

line(0,midy,maxx,midy);

}

void main()

{

int x,y,z,o,x1,x2,y1,y2;

int gd=DETECT,gm;

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\tc\\bgi");

//setfillstyle(0,getmaxcolor());

maxx=getmaxx();

maxy=getmaxy();

midx=maxx/2;

midy=maxy/2;

 

axis();

 

bar3d(midx+50,midy-100,midx+60,midy-90,5,1);

outtextxy(midx + 30,midy-80, "Before Scalling Object");

printf("Enter scaling factors: ");

scanf("%d%d%d", &x,&y,&z);

//axis();

printf("After scaling");

bar3d(midx+(x*50),midy-(y*100),midx+(x*60),midy-(y*90),5*z,1);

outtextxy(midx+(x*30),midy-(y*80), "After scalling Image");

//axis();

getch();

closegraph();

}

 

 

 

 

8.1.3        For Rotation

 

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

int maxx,maxy,midx,midy;

void axis()

{

getch();

cleardevice();

line(midx,0,midx,maxy);

line(0,midy,maxx,midy);

}

void main()

{

int x,y,z,o,x1,x2,y1,y2;

int gd=DETECT,gm;

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\tc\\bgi");

//setfillstyle(0,getmaxcolor());

maxx=getmaxx();

maxy=getmaxy();

midx=maxx/2;

midy=maxy/2;

axis();

bar3d(midx+50,midy-100,midx+60,midy-90,5,1);

outtextxy(midx+30,midy-80,"Object");

printf("Enter rotating angle:");

scanf("%d",&o);

 x1=50*cos(o*3.14/180)-100*sin(o*3.14/180);

 y1=50*sin(o*3.14/180)+100*cos(o*3.14/180);

 x2=60*cos(o*3.14/180)-90*sin(o*3.14/180);

 y2=60*sin(o*3.14/180)+90*cos(o*3.14/180);

 axis();

printf("After rotation about z axis.");

bar3d(midx+x1,midy-y1,midx+x2,midy-y2,5,1);

axis();

printf("After rotation  about x axis.");

bar3d(midx+50,midy-x1,midx+60,midy-x2,5,1);

outtextxy(midx+30,midy+40,"Object");

axis();

printf("After rotation about y axis.");

bar3d(midx+x1,midy-100,midx+x2,midy-90,5,1);

outtextxy(midx+x1+20,midy-80,"Object");

getch();

closegraph();

}

 

LAB 9

 

9.1       Program to implement of flood fill and boundary fill algorithm.

 

9.1.1        For flood fill algorithm

 

#include<stdio.h>

#include<graphics.h>

#include<dos.h>

void floodFill(int x,int y,int oldcolor,int newcolor)

{

if(getpixel(x,y) == oldcolor)

{

putpixel(x,y,newcolor);

floodFill(x+1,y,oldcolor,newcolor);

floodFill(x,y+1,oldcolor,newcolor);

floodFill(x-1,y,oldcolor,newcolor);

floodFill(x,y-1,oldcolor,newcolor);

}

}

 

int main()

{

int gm,gd=DETECT,radius;

int x,y;

printf("Enter x and y positions for circle\n");

scanf("%d%d",&x,&y);

printf("Enter radius of circle\n");

scanf("%d",&radius);

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

circle(x,y,radius);

floodFill(x,y,0,15);

delay(5000);

closegraph();

return 0;

}

 

9.1.2        For boundary fill algorithm

 

#include<stdio.h>

#include<graphics.h>

#include<dos.h>

void boundaryfill(int x,int y,int f_color,int b_color)

{

if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color)

{

putpixel(x,y,f_color);

boundaryfill(x+1,y,f_color,b_color);

boundaryfill(x,y+1,f_color,b_color);

boundaryfill(x-1,y,f_color,b_color);

boundaryfill(x,y-1,f_color,b_color);

}

}

 

int main()

{

int gm,gd=DETECT,radius;

int x,y;

printf("Enter x and y positions for circle\n");

scanf("%d%d",&x,&y);

printf("Enter radius of circle\n");

scanf("%d",&radius);

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

circle(x,y,radius);

boundaryfill(x,y,4,15);

delay(5000);

closegraph();

return 0;

}


 

CONLUSION

 <Details summary of your lab report>


REFERENCES

 

[1]. http://www.programsformca.com/2010/11/3d-transformations-translation-rotation.html.

[2]. Computer Graphic and Animation BCA 5th Semester, Authors: Bhupendra Singh Saud, Indra Chaudhary.

[3]. https://www.javatpoint.com/

[4]. https://www.thiyagaraaj.com/tutorials/computer-graphics-programs-using-c-programming/8-3d-animation-computer-graphics-programs/1-3d-translation-program-using-c-programming

[5]. https://www.thecrazyprogrammer.com/2017/02/flood-fill-algorithm-in-c.html

 

 Notes: The output should be added after run this code in turboC++, and DevC++.


Comments

Popular Posts

Contact Us

Name

Email *

Message *

Followers