0% found this document useful (0 votes)
87 views

PROGRAM CODING: (Line Attributes)

The document contains code for drawing lines, ellipses, and circles in C graphics programming and implementing different attributes such as style, width, color, and fill patterns. It includes code to set line styles, widths, and colors. It also includes code for drawing dotted, dashed and solid ellipses and circles using midpoint ellipse algorithm and Bresenham's circle algorithm. Functions are used to implement different fill patterns for circles. The user is prompted to choose different attributes to implement and view the output.

Uploaded by

anon_341909881
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

PROGRAM CODING: (Line Attributes)

The document contains code for drawing lines, ellipses, and circles in C graphics programming and implementing different attributes such as style, width, color, and fill patterns. It includes code to set line styles, widths, and colors. It also includes code for drawing dotted, dashed and solid ellipses and circles using midpoint ellipse algorithm and Bresenham's circle algorithm. Functions are used to implement different fill patterns for circles. The user is prompted to choose different attributes to implement and view the output.

Uploaded by

anon_341909881
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

PROGRAM CODING: (line attributes)

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<string.h>
#include<stdlib.h>
void main()
{
int style,color,width,ch;
int xa,ya,xb,yb,loop;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
printf("\n \t << IMPLEMENTATION OF LINE ATTRIBUTES >> ");
printf("\n enter starting points:");
scanf("%d%d",&xa,&ya);
printf("\n enter ending points:");
scanf("%d%d",&xb,&yb);
do
{
clrscr();
cleardevice();
printf("\nenter choice u want to change \n 1.style \n 2.width \n 3.color");
scanf("%d",&ch);
switch(ch)
{
case 1:
outtextxy(xa+100,ya,"SOLID");
setlinestyle(SOLID_LINE,0,2);
line(xa+120,ya,xb+120,yb);

outtextxy(xa+150,ya,"DOTTED");
setlinestyle(DOTTED_LINE,0,2);
line(xa+170,ya,xb+170,yb);

outtextxy(xa+200,ya,"DASHED");
setlinestyle(DASHED_LINE,0,2);
line(xa+220,ya,xb+220,yb);

outtextxy(xa+250,ya,"DOTTED DASHED");
setlinestyle(USERBIT_LINE,64250,1);
line(xa+270,ya,xb+270,yb);
break;

case 2:
printf(" \n enter width:");
scanf("%d",&width);
setlinestyle(SOLID_LINE,0,width);
line(xa+50,ya+10,xb+50,yb+10);
break;

case 3:
printf("\n enter color:");
scanf("%d",&color);
setcolor(color);
line(xa,ya,xb,yb);
}
printf("\n do u wish to continue ? 1.yes \n 2.no");
scanf("%d",&loop);
}
while(loop==1);
getch();
}

































OUTPUT:









PROGRAM CODE: (ellipse attributes)
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void plotpoint(int xc,int yc,int x,int y,int col)
{
putpixel(xc+x,yc+y,col);
putpixel(xc+x,yc-y,col);
putpixel(xc-x,yc+y,col);
putpixel(xc-x,yc-y,col);
}
void inellipse(int xc,int yc,int rx,int ry,int c,int col)
{
float x=0.0,y=0.0,p,px,py,rx2,rx3,ry2,ry3;
int i=0,j=0,ch,u;
rx2=rx*rx;
ry2=ry*ry;
rx3=2*rx2;
ry3=2*ry2;
x=0;
y=ry;
px=0;
py=rx3*y;
plotpoint(xc,yc,x,y,col);
p=ry2-(rx2*y)+(0.25*rx2);
while(px<py)
{
x++;
px+=ry3;
if(p<0)
p+=ry2+px;
else
{
y--;
py- =rx3;
p+=ry2+px-py;
}
if(c==1)
{
i=x;
if(i%5==0)
{ plotpoint(xc,yc,x,y,col); }

}
else if(c==2)
{
j=x;
u=j%15;
if(u<6)
plotpoint(xc,yc,x,y,col);
}
else
plotpoint(xc,yc,x,y,col);
}
p=ry2*(x+0.5)*(x+0.5)+rx2*(y-1)*(y-1)-rx2*ry2;
while(y>0)
{
y--;
py-=rx3;
if(p>0)
p+=rx2-py;
else
{
x++;
px+=ry3;
p+=rx2-py+px;
}

if(c==1)
{
i=y;
if(i%5==0)
{
plotpoint(xc,yc,x,y,col);
}
}
else if(c==2)
{
j=y;
u=j%15;
if(u<6)
plotpoint(xc,yc,x,y,col);
}
else
plotpoint(xc,yc,x,y,col);
}
}
void main()
{
float xc,yc,rx,ry;
int col,ch,c,rad;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
printf("\n midpoint ellipse drawing algorithm") ;
printf("\n enter center of ellipse");
scanf("%f%f",&xc,&yc);
printf("\n enter radius");
scanf("%f%f",&rx,&ry);
do
{
clrscr(); cleardevice();
printf("\n <<implementation of ellipse attributes>>");
printf("\n1.dotted \n2.dashed\n 3.solid \n 4.color\n 5.fill \n enter choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
inellipse(xc,yc,rx,ry,ch,1);break;
case 2:
inellipse(xc,yc,rx,ry,ch,2);break;
case 3:
inellipse(xc,yc,rx,ry,ch,3);break;
case 4:
printf("\n enter color:");
scanf("%d",&col);
inellipse(xc,yc,rx,ry,ch,col);
break;
case 5:
outtextxy(xc,yc-100,"SOLID_FILL");
setfillstyle(SOLID_FILL,col);
inellipse(xc,yc,rx,ry,ch,col);
fillellipse(xc,yc,rx,ry);
outtextxy(xc+100,yc-100,"INTERLEAVE-FILL");
setfillstyle(INTERLEAVE_FILL,col);
inellipse(xc+150,yc,rx,ry,ch,col);
fillellipse(xc+150,yc,rx,ry);
break;
}
printf("do u wish to continue 1.yes \n 2.no");
scanf("%d",&c);
}
while(c==1);

getch();
}







OUTPUT:
























PROGRAM CODE: (circle attributes)
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void plotpoint(int xlen,int ylen,int x,int y,int col)
{
putpixel(xlen+x,ylen+y,col);
putpixel(xlen-x,ylen+y,col);
putpixel(xlen+x,ylen-y,col);
putpixel(xlen-x,ylen-y,col);
putpixel(xlen+y,ylen+x,col);
putpixel(xlen-y,ylen+x,col);
putpixel(xlen+y,ylen-x,col);
putpixel(xlen-y,ylen-x,col);
}

void incircle(int xc,int yc,int rad,int c,int col)
{
int x,y,p,u;
x=0;y=rad;
plotpoint(xc,yc,x,y,col);
p=1-rad;

while(x<y)
{
if(p<0)
` x++;
else
{
x++; y--;
}
if(p<0)
p+=2*x-1;
else
p+=2*(x-y)+1;
if(c==1)
{
if(x%5==0)
plotpoint(xc,yc,x,y,col);
}
else if(c==2)
{
u=x%15;
if(u<6)
plotpoint(xc,yc,x,y,col);
}
else
plotpoint(xc,yc,x,y,col);
}
}
void main()
{
int rad;
int gd=DETECT,gm,xc,yc,y,color,ch,a=100,b=200,r=25;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
printf("\n \t<<IMPLEMENTATION OF CIRCLE ATTRIBUTES>>");
printf("\n enter radius and center of circle:");
scanf("%d%d%d",&xc,&yc,&rad);
do
{
clrscr();
cleardevice();
printf("\n \t<< IMPLEMENTATION OF CIRCLE ATTRIBUTES >> \n 1.dotted\n 2.dashed
\n3.solid \n4.circlecolour \n 5.fill pattern");
printf("\n enter ur choice:");
scanf("%d",&ch);



switch(ch)
{
case 1:
incircle(xc,yc,rad,ch,15);break;
case 2:
incircle(xc,yc,rad,ch,15);break;
case 3:
incircle(xc,yc,rad,ch,15);break;
case 4:
printf("\n enter colour:\t");
scanf("%d",&color);
setcolor(color);
incircle(xc,yc,rad,ch,color);
break;
case 5:
setfillstyle(LINE_FILL,1);
circle(a,b,r);
fillellipse(a,b,r,r);
outtextxy(a-50,b+50,"LINE_FILL");

setfillstyle(EMPTY_FILL,2);
circle(a,b+100,r);
fillellipse(a,b+100,r,r);
outtextxy(a-50,b+150,"EMPTY_FILL");

setfillstyle(LTSLASH_FILL,3);
circle(a,b+200,r);
fillellipse(a,b+200,r,r);
outtextxy(a-50,b+250,"LTSLASH_FILL");

setfillstyle(SLASH_FILL,4);
circle(a+200,b+100,r);
fillellipse(a+200,b+100,r,r);
outtextxy(a+150,b+150,"SLASH_FILL");
}
printf("\n do u wish to continue 1.yes \n 2.no");
scanf("%d",&y);
}
while(y==1);
getch();
}


























OUTPUT:

You might also like