0% found this document useful (0 votes)
2 views6 pages

Lab 1

The document contains three WAC programs demonstrating graphics functions in C++. The first program implements the midpoint ellipse algorithm, the second program uses the flood fill function to create a hut, and the third program creates and colors a balloon. Each program includes necessary libraries, initialization of graphics mode, and drawing commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Lab 1

The document contains three WAC programs demonstrating graphics functions in C++. The first program implements the midpoint ellipse algorithm, the second program uses the flood fill function to create a hut, and the third program creates and colors a balloon. Each program includes necessary libraries, initialization of graphics mode, and drawing commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.WAC program to draw a ellipse by using mid point ellipse algorithm.

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

void main()

int gd=DETECT,gm;

initgraph(&gd,&gm,"");

float xc,yc,x,y,xr,yr,f;

cout<<"enter xcenter,ycenter,xradius & yradius";

cin>>xc>>yc>>xr>>yr;

x=0;

y=yr;

f=(yr*yr)+(xr*xr)/4-(xr*xr)*yr;

while(2*(yr*yr)*x<=2*(xr*xr)*y)

if(f<=0)

f=f+(3+(2*x))*(yr*yr);

x++;

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

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

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

else

f=f+3*(yr*yr)+2*x*(yr*yr)+2*(xr*xr)-2*y*(xr*xr);

x++;

y--;

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

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

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

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

f=(yr*yr)/4-2*(xr*xr)*yr+(xr*xr);

while(y>=0)

if(f<=0)

f=f+(3-(2*y))*(xr*xr);

x++;

y--;

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

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

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

else

f=f+2*(yr*yr)+2*x*(yr*yr)+3*(xr*xr)-2*y*(xr*xr);

y--;

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

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

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

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

getch();

}
2.WAC program to implement floodfill function(Hut)
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
setcolor(GREEN);
line(60,10,20,100);
line(60,10,100,100);
line(20,100,100,100);
line(60,10,290,10);
line(290,10,320,100);
line(100,100,320,100);
line(20,100,20,340);
line(100,100,100,340);
line(20,340,100,340);
line(320,100,320,340);
line(100,340,320,340);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(319,339,GREEN);
floodfill(61,291,GREEN);
floodfill(61,11,GREEN);
floodfill(21,99,GREEN);
setcolor(GREEN);
line(40,250,40,340);
line(80,250,80,340);
line(40,250,80,250);
setcolor(BROWN);
circle(60,55,10);
line(140,200,140,240);
line(140,200,265,200);
line(265,200,265,240);
line(140,240,265,240);
setfillstyle(HATCH_FILL,BROWN);
floodfill(41,251,GREEN);
setfillstyle(SOLID_FILL,BROWN);
floodfill(61,56,BROWN);
floodfill(141,201,BROWN);
getch();
}
Output:

3.WAC Program to create a ballon and color it.

#include<stdio.h>

#include<graphics.h>

int main()

intgraphdriver=0,graphmode;

initgraph(&graphdriver,&graphmode,NULL);

setcolor(RED);

fillellipse(75,200,50,45);

setcolor(YELLOW);

line(75,246,75,450);

getch();

closegraph();
return 0;

You might also like