You are on page 1of 13

PROJECT REPORT

COMPUTER GRAPHICS

PROJECT NAME: UI 3D SHAPES TRANSFORMATION


USING COLOR PICKER

PROJECT CREATED BY: WAJAHAT AHMED (CSC-17S-113)

SECTION: 6D-EVENING

PROJECT SUPERVISOR: SIR IRFAN ALI KANDHRO


ACKNOWLEDGEMENT
A teacher isn’t just an instructor. They are a mentor, a guide, a counselor, a
protector and a large part of the village kids need to grow up grandly. The man
who gave inspiration, strength and developed our mind for programing is sir Irfan
Ali kandhro. Whenever we need a help, he always available for us. We are
grateful to sir Irfan ali kandhro . We are also thankful to our respected HOD who
gave us a suspicious faculty and give also create a good relation between student
and teachers. Now I’m very thankful to our most respected DEAN of our
department who gave us a dynamic environment and gave labs and PCs for
individual use. We are appreciating you for your mind-blowing effort for our
department of computer science.
3D TRANSFORMATION
In Computer Graphics 3D-Transformation is a process of modifying and re-positioning the
existing graphics. 
 3D Transformations take place in a three dimensional plane.
 3D Transformations are important and a bit more complex than 2D Transformations.
 Transformations are helpful in changing the position, size, orientation, shape etc of the
object

3D SCALING:
In computer graphics, scaling is a process of modifying or altering the size of objects

 Scaling may be used to increase or reduce the size of object.


 Scaling subjects the coordinate points of the original object to change.
 Scaling factor determines whether the object size is to be increased or reduced.
 If scaling factor > 1, then the object size is increased.
 If scaling factor < 1, then the object size is reduced.
 
Consider a point object O has to be scaled in a 3D plane.
 
Let-
 Initial coordinates of the object O = (Xold, Yold,Zold)
 Scaling factor for X-axis = Sx
 Scaling factor for Y-axis = Sy
 Scaling factor for Z-axis = Sz
 New coordinates of the object O after scaling = (Xnew, Ynew, Znew)
 
This scaling is achieved by using the following scaling equations-
 Xnew = Xold x Sx
 Ynew = Yold x Sy
 Znew = Zold x Sz

3D TRANSLATION:
In Computer graphics, 3D Translation is a process of moving an object from one position to
another in a three dimensional plane.

Consider a point object O has to be moved from one position to another in a 3D plane.
 
Let-
 Initial coordinates of the object O = (Xold, Yold, Zold)
 New coordinates of the object O after translation = (Xnew, Ynew, Zold)
 Translation vector or Shift vector = (Tx, Ty, Tz)
 
Given a Translation vector (Tx, Ty, Tz)-
 Tx defines the distance the Xold coordinate has to be moved.
 Ty defines the distance the Yold coordinate has to be moved.
 Tz defines the distance the Zold coordinate has to be moved.
SOURCE CODE
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
union REGS i,o;
//floodfill
void title(){
int x,y,xc=319,yc=239,c=2,lp=0,j=0;
int x2,y2,x3,y3;
settextstyle(6,0,1);
outtextxy(xc-33,yc-10,"WELCOME");
while(lp<10)
{
j++;
sound(j+(250*lp));
x=xc+(60 * cos (j * 3.142/1));
y=yc+(60 * sin (j * 3.142/1));
x2=xc+(80 * cos (j * 3.142/2));
y2=yc+(80 * -sin (j * 3.142/2));

x3=xc+(100 * cos (j * 3.142/0.5));


y3=yc+(100 * sin (j * 3.142/0.5));

if (j==8128){

j=0;
lp++;
if (c==2){
c=0;
}else c=2;
nosound();
}

putpixel(x,y,c);
putpixel(x2,y2,c);
putpixel(x3,y3,c);

delay(0.5);
}
}
int flood(int x, int y, int new_col, int old_col)
{if(x>639 || x<1 || y>479 || y<1){return 0;}
if(getpixel(x, y) == old_col){
putpixel(x, y, new_col);
flood(x + 1, y, new_col, old_col);
flood(x - 1, y, new_col, old_col);
flood(x, y + 1, new_col, old_col);
flood(x, y - 1, new_col, old_col);
return 1;
}
else return 0;
}

//functions
int mInit()
{i.x.ax=1;int86(0x33,&i,&o);return 1;}
void mpos(int &xpos,int &ypos,int &click)
{i.x.ax=3;int86(51,&i,&o);click=o.x.bx;xpos=o.x.cx;ypos=o.x.dx;}
void restrictmouseptr(int x1, int y1, int x2, int y2)
{i.x.ax = 7;i.x.cx = x1;i.x.dx = x2;int86(0X33, &i, &o);
i.x.ax = 8;i.x.cx = y1;i.x.dx = y2;int86(0X33, &i, &o);}
//draw
void triangle(int x1,int y1,int x2,int y2,int x3,int y3)
{
int poly[8]={x1,y1,x2,y2,x3,y3,x1,y1};
drawpoly(4,poly);
}
void drawobj(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4)
{
int obj1[10]={x1,y1,x2,y2,x3,y3,x4,y4,x1,y1};
drawpoly(5,obj1);
}
//end functions
void main()
{
int gd=DETECT,gm;
int x1,x2,x3,x4,y1,y2,y3,y4;
//int xc=0,yc=0;
int ocol=15,fcol=0;
int mx=0,my=0,mc=0,mt=0,md=1000,scale=0,clkd=0;
initgraph(&gd,&gm, "c:\\turboc3\\bgi");
title();
cleardevice();
//INTERFACE
setcolor(7);
rectangle(0,0,639,479);
rectangle(10,10,629,340);
rectangle(10,350,629,469);
setfillstyle(1,8);
floodfill(2,2,7);

//menu design
settextstyle(1,0,1);
outtextxy(20,350,"Translation");
rectangle(60,380,80,400);//up
triangle(63,397,77,397,70,383);

rectangle(60,430,80,450);//down
triangle(63,433,77,433,70,447);

rectangle(35,405,55,425);//left
triangle(52,408,52,422,38,415);
rectangle(85,405,105,425);//right
triangle(88,408,88,422,102,415);

//seprate
line(135,350,135,469);
line(145,350,145,469);
//scale
settextstyle(1,0,1);
outtextxy(170,350,"Scaling");
rectangle(185,380,215,410);//+
rectangle(185,420,215,450);//-
settextstyle(10,0,2);
outtextxy(192,368,"+");
outtextxy(192,408,"-");
// end scale
line(255,350,255,469);
line(265,350,265,469);
//color
//outline
settextstyle(1,0,1);
outtextxy(280,350,"COLOR");
rectangle(275,405-10,295,425-10);//left
setfillstyle(1,ocol);
rectangle(393-20,405-12,417-20,425-8);//col
bar(395-20,405-10,415-20,425-10);//col
rectangle(315,405-10,335,425-10);//right
triangle(292,408-10,292,422-10,277,415-10);//l
triangle(317,408-10,317,422-10,332,415-10);//r
//filler
settextstyle(1,0,1);
outtextxy(280,350,"COLOR");
outtextxy(340,390,"Out");
outtextxy(340,420,"Fill");
rectangle(275,405+20,295,425+20);//left
setfillstyle(1,fcol);
rectangle(393-20,405+18,417-20,425+22);
bar(395-20,405+20,415-20,425+20);//col
rectangle(315,405+20,335,425+20);//right
triangle(292,408+20,292,422+20,277,415+20);//l
triangle(317,408+20,317,422+20,332,415+20);//r

mInit();
restrictmouseptr(10,350,629,469);
setcolor(15);
x1=20;y1=20;x2=60;y2=20;x3=60;y3=60;x4=20;y4=60;
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
while(!kbhit())
{
// xc=floor((x1+x2)/2);
// yc=floor((y1+y2)/2);

mpos(mx,my,mc);
if(mc!=1){mt=0;clkd=0;}
//if(mc==1){mt++;}
if(mt<md){mt+=2;}

//menu translate up
if(mx>=60 && my>=380 && mx<=80 && my<=400 && mt==md)
{
sound(y1*30);
//printf("UP ");
if(y1>14 && y2>14 && y3>14 && y4>14){
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
y1--;y2--;y3--;y4--;
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setfillstyle(1,fcol);
bar(x1+1,y1+1,x3-1,y3-1);
}
}
//down
else if(mx>=60 && my>=430 && mx<=80 && my<=450 && mt==md)
{
sound(y1*30);
if(y1<336 && y2<336 && y3<336 && y4<336){
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
y1++;y2++;y3++;y4++;
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setfillstyle(1,fcol);
bar(x1+1,y1+1,x3-1,y3-1);
}

}
//left
else if(mx>=35 && my>=405 && mx<=55 && my<=442 && mt==md)
{
sound(x1*30);
if(x1>14 && x2>14 && x3>14 && x4>14){
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
x1--;x2--;x3--;x4--;
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setfillstyle(1,fcol);
bar(x1+1,y1+1,x3-1,y3-1);
}
}
//right
else if(mx>=85 && my>=405 && mx<=105 && my<=425 && mt==md)
{
sound(x1*30);
if(x1<624 && x2<624 && x3<624 && x4<624){
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
x1++;x2++;x3++;x4++;
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setfillstyle(1,fcol);
bar(x1+1,y1+1,x3-1,y3-1);
}
}
//scale +++
else if(mx>=185 && my>=380 && mx<=215 && my<=410 && mt==md)
{
if(x1<624 && x2<624 && x3<624 && x4<624 && x1>14 && x2>14 && x3>14 &&
x4>14 && y1>14 && y2>14 && y3>14 && y4>14 && y1<336 && y2<336 && y3<336 &&
y4<336){
scale++;
sound(scale*50);
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
x1--;x2++;x3++;x4--;
y1--;y2--;y3++;y4++;
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setfillstyle(1,fcol);
bar(x1+1,y1+1,x3-1,y3-1);
}
}
//scale ---
else if(mx>=185 && my>=420 && mx<=215 && my<=450 && mt==md)
{
if(scale>0) {
scale--;
sound(scale*50);
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
x1++;x2--;x3--;x4++;
y1++;y2++;y3--;y4--;
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setfillstyle(1,fcol);
bar(x1+1,y1+1,x3-1,y3-1);
}
}
//outline color
//col
//left
else if(mx>=275 && my>=395 && mx<=295 && my<=415 && clkd==0 && mc==1)
{
clkd=1;
if(ocol>0) {
ocol--;
}else {ocol=15;}
if (ocol==fcol){ocol--;}
setfillstyle(1,ocol);
bar(395-20,405-10,415-20,425-10);
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setfillstyle(1,fcol);
floodfill(x1+5,y1+5,ocol);
}
//right
else if(mx>=315 && my>=395 && mx<=335 && my<=415 && clkd==0 && mc==1)
{
clkd=1;
if(ocol<15) {
ocol++;
}else{ocol=0;}
if (ocol==fcol){ocol++;}

setfillstyle(1,ocol);
bar(395-20,405-10,415-20,425-10);
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setfillstyle(1,fcol);
floodfill(x1+5,y1+5,ocol);
}
//Fillcolor
//left
else if(mx>=275 && my>=425 && mx<=295 && my<=445 && clkd==0 && mc==1)
{
clkd=1;
if(fcol>0) {
fcol--;
}else {fcol=15;}
if (fcol==ocol){fcol--;}
setfillstyle(1,fcol);
bar(395-20,405+20,415-20,425+20);//col
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
floodfill(x1+5,y1+5,ocol);
}
//right
else if(mx>=315 && my>=425 && mx<=335 && my<=445 && clkd==0 && mc==1)
{
clkd=1;
if(fcol<15) {
fcol++;
}else {fcol=0;}
if (fcol==ocol){fcol++;}
setfillstyle(1,fcol);
bar(395-20,405+20,415-20,425+20);//col
setcolor(0);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
setcolor(ocol);
drawobj(x1,y1,x2,y2,x3,y3,x4,y4);
floodfill(x1+5,y1+5,ocol);
}

nosound();
if(mt>=md){mt=0;}
}

closegraph();
}

You might also like