Sie sind auf Seite 1von 5

1. WAP to generate a Pixel and move it across the screen.

2. Implementation of line generation using slope’s method, DDA


3. Implementation of line generation using Bresenham’s algorithms.
4. Implementation of circle generation using Mid-point method
5. Implementation of circle generation using Bresenham’s algorithm.
6. Implementation of polygon filling using Flood-fill
7. Implementation of polygon filling using Boundary-fill.

Mid-point Ellipse drawing:


// C Implementation for drawing ellipse
#include <graphics.h>
int main()
{
// gm is Graphics mode which is a computer display
// mode that generates image using pixels.
// DETECT is a macro defined in "graphics.h" header file
int gd = DETECT, gm;
// location of ellipse
int x = 250, y = 200;
// here is the starting angle
// and end angle
int start_angle = 0;
int end_angle = 360;
// radius from x axis and y axis
int x_rad = 100;
int y_rad = 50;

// initgraph initializes the graphics system


// by loading a graphics driver from disk
initgraph(&gd, &gm, "..\\BGI/");
// ellipse fuction
ellipse(x, y, start_angle, end_angle, x_rad, y_rad);
getch();
// closegraph function closes the graphics
// mode and deallocates all memory allocated
// by graphics system .
closegraph();
return 0;
}

1. Implementation of polygon filling using Flood-fill, Boundary-fill and Scan-line algorithms.


a.) Flood-fill:
#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);
}
}
//getpixel(x,y) gives the color of specified pixel

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;
}
b.) Boundary fill:
#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);
}
}
//getpixel(x,y) gives the color of specified pixel
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;
}

Das könnte Ihnen auch gefallen