Fundamental Graphics Functions
Fundamental Graphics Functions
p=2*dx-dy; if(y1>y2) { x=x2; y=y2; yend=y2; } putpixel(x,y,2); for(i=y;i<yend;i++) { y+=1; if(p<0) p+=2*dx; else { x+=1; p+=2*(dx-dy); } putpixel(x,y,2); } } }
getch();
#include<stdio.h> #include<conio.h> #include<graphics.h> #include<process.h> #include<math.h> void TriAngle(int x1,int y1,int x2,int y2,int x3,int y3); void Rotate(int x1,int y1,int x2,int y2,int x3,int y3); void main() { int gd=DETECT,gm; int x1,y1,x2,y2,x3,y3; initgraph(&gd,&gm," "); 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); TriAngle(x1,y1,x2,y2,x3,y3); getch(); cleardevice(); Rotate(x1,y1,x2,y2,x3,y3); setcolor(1); TriAngle(x1,y1,x2,y2,x3,y3); getch();
void TriAngle(int x1,int y1,int x2,int y2,int x3,int y3) { line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); } void Rotate(int x1,int y1,int x2,int y2,int x3,int y3) { int x,y,a1,b1,a2,b2,a3,b3,p=x2,q=y2; float Angle; printf("Enter the angle for rotation:"); scanf("%f",&Angle); cleardevice(); Angle=(Angle*3.14)/180; a1=p+(x1-p)*cos(Angle)-(y1-q)*sin(Angle); b1=q+(x1-p)*sin(Angle)+(y1-q)*cos(Angle); a2=p+(x2-p)*cos(Angle)-(y2-q)*sin(Angle); b2=q+(x2-p)*sin(Angle)+(y2-q)*cos(Angle); a3=p+(x3-p)*cos(Angle)-(y3-q)*sin(Angle); b3=q+(x3-p)*sin(Angle)+(y3-q)*cos(Angle); printf("Rotate"); TriAngle(a1,b1,a2,b2,a3,b3); }
#include<conio.h> #include<graphics.h> #include<process.h> #include<math.h> int x1,y1,x2,y2,x3,y3,mx,my; void draw(); void tri(); void main() { int gd=DETECT,gm; int c; initgraph(&gd,&gm,"d:\\tc\\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); cleardevice(); draw(); getch(); tri(); getch(); } void draw() { line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); } void tri() { int x,y,a1,a2,a3,b1,b2,b3; printf("Enter the Transaction coordinates"); scanf("%d%d",&x,&y); cleardevice(); a1=x1+x; b1=y1+y; a2=x2+x; b2=y2+y; a3=x3+x; b3=y3+y; line(a1,b1,a2,b2); line(a2,b2,a3,b3); line(a3,b3,a1,b1); }
#include<stdio.h> #include<conio.h> #include<graphics.h> #include<process.h> #include<math.h> void RectAngle(int x,int y,int Height,int Width); void Translate(int x,int y,int Height,int Width); void main() { int gd=DETECT,gm; int x,y,Height,Width; initgraph(&gd,&gm," "); printf("Enter the First point for the Rectangle:"); scanf("%d%d",&x,&y); printf("Enter the Height&Width for the Rectangle:"); scanf("%d%d",&Height,&Width); RectAngle(x,y,Height,Width); getch(); cleardevice(); Translate(x,y,Height,Width); RectAngle(x,y,Height,Width); getch(); } void RectAngle(int x,int y,int Height,int Width) { line(x,y,x+Width,y); line(x,y,x,y+Height); line(x+Width,y,x+Width,y+Height); line(x,y+Height,x+Width,y+Height); } void Translate(int x,int y,int Height,int Width) { int Newx,Newy,a,b; printf("Enter the Transaction coordinates"); scanf("%d%d",&Newx,&Newy); cleardevice(); a=x+Newx; b=y+Newy; RectAngle(a,b,Height,Width); }
#include<stdio.h> #include<conio.h> #include<math.h> #include<process.h> #include<graphics.h> int x1,x2,y1,y2,mx,my,depth; void draw(); void scale(); void main() { int gd=DETECT,gm,c; initgraph(&gd,&gm,"d:\\tc\\bgi"); printf("\n\t\t3D Transformation Scalling\n\n"); printf("\nEnter 1st top value(x1,y1):"); scanf("%d%d",&x1,&y1); printf("Enter right bottom value(x2,y2):"); scanf("%d%d",&x2,&y2); depth=(x2-x1)/4; mx=(x1+x2)/2; my=(y1+y2)/2; draw(); getch(); cleardevice(); scale(); getch(); } void draw() { bar3d(x1,y1,x2,y2,depth,1); } void scale() { int x,y,a1,a2,b1,b2,dep; printf("\n\n Enter scalling co-ordinates:"); scanf("%d%d",&x,&y); a1=mx+(x1-mx)*x; a2=mx+(x2-mx)*x; b1=my+(y1-my)*y; b2=my+(y2-my)*y; dep=(a2-a1)/4; bar3d(a1,b1,a2,b2,dep,1); setcolor(5); draw(); }
#include<stdio.h> #include<conio.h> #include<math.h> #include<process.h> #include<graphics.h> int x1,x2,y1,y2,mx,my,depth; void draw(); void rotate(); void main() { int gd=DETECT,gm,c; initgraph(&gd,&gm,"d:\\tc\\bgi"); printf("\n3D Transformation Rotating\n\n"); printf("\nEnter 1st top value(x1,y1):"); scanf("%d%d",&x1,&y1); printf("Enter right bottom value(x2,y2):"); scanf("%d%d",&x2,&y2); depth=(x2-x1)/4; mx=(x1+x2)/2; my=(y1+y2)/2; draw(); getch(); cleardevice(); rotate(); getch(); } void draw() { bar3d(x1,y1,x2,y2,depth,1); } void rotate() { float t; int a1,b1,a2,b2,dep; printf("Enter the angle to rotate="); scanf("%f",&t); t=t*(3.14/180); a1=mx+(x1-mx)*cos(t)-(y1-my)*sin(t); a2=mx+(x2-mx)*cos(t)-(y2-my)*sin(t); b1=my+(x1-mx)*sin(t)-(y1-my)*cos(t); b2=my+(x2-mx)*sin(t)-(y2-my)*cos(t); if(a2>a1) dep=(a2-a1)/4; else dep=(a1-a2)/4; bar3d(a1,b1,a2,b2,dep,1); setcolor(5); //draw(); }