CG Practicals

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

PRACTICAL 10:IMPLEMENT SCALING

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>
#include<math.h>
int x1,y1,x2,y2,x3,y3;
void draw();
void scale();
void main();
{
int gd=DETECT,gm;
int c;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("Enter the 1st point for the triangle:");
scanf("%d%d",&x1,&y1);
printf("Enter the 2nd point for the triangle:");
scanf("%d%d",&x2,&y2);
printf("Enter the 3rd point for the triangle:");
scanf("%d%d",&x3,&y3);
draw();
scale();
}
vpoid main()
{
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
}
void scale();
{
int x,y;
int mx,my;
printf("Enter the scaling factor(x,y):");
scanf("%d%d",&x,&y);
mx=(x1+x2+x3)/3;
my=(y1+y2+y3)/3;
cleardevice();
int a1,a2,a3,b1,b2,b3;
a1=mx+(x1-mx)*x;
b1=my+(y1-my)*y;
a2=mx+(x2-mx)*x;
b2=my+(y2-my)*y;
a3=mx+(x3-mx)*x;
b3=my+(y3-my)*y;
line(a1,b1,a2,b2);
line(a2,b2,a3,b3);
line(a3,b3,a1,b1);
draw();
getch();
}

PRACTICAL 11:BRESHNHAMS LINE DRAWING ALGORITHM


#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void drawline(int x0,int y0,int x1,int y1)
{
int dx,dy,p,x,y;
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1)
{
if(p>=0)
{
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
}
else
{
putpixel(x,y,7);
p=p+2*dy;
}
x=x+1;
}
}
void main()
{
int gdriver=DETECT,gmode,error,x0,y0,x1,y1;
initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");
printf("Enter coordinate of first point:");
scanf("%d%d",&x0,&y0);
printf("Enter coordinate of second point:");
scanf("%d%d",&x1,&y1);
drawline(x0,y0,x1,y1);
getch();
closegraph();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy