www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

# CS602 Assignment No 02 Fall 2020 Solution / Discussion Due Date: 17-12-2020

CS602 Assignment No 02 Fall 2020 Solution / Discussion Due Date: 17-12-2020

 Assignment No. 02Semester: Fall 2020 CS602: Computer Graphics Total Marks: 20 Due Date: Dec 17, 2020

Views: 899

### Replies to This Discussion

Share the Assignment Questions & Discuss Here....

Stay touched with this discussion, Solution idea will be uploaded as soon as possible in replies here before the due date.

cs602 assignment no solution files in word and cpp format

CS602_Assignment_No_02_Solution_Fall_2020

CS602-Assignment-02-solution-fall-2020.cpp

cs602 2nd assignment 100% correct solution

CS602-2nd-assignment-100%-correct-solution

Cs602 Solution

Soltion No 1

#include <graphics.h>

#include <stdio.h>

void flood(int x, int y, int new_col, int old_col)

{

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);

}

}

int main()

{

int gd, gm = DETECT;

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

int top, left, bottom, right;

top = left = 50;

bottom = right = 300;

rectangle(left, top, right, bottom);

int x = 51;

int y = 51;

int newcolor = 15;

int oldcolor = 0;

flood (x, y, newcolor, oldcolor);

getch();

return 0;

}

Solution No 2

#include <graphics.h>

int main()

{

int gd = DETECT, gm;

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

int x_circle = 250;

int y_circle = 250;

int border_color=WHITE;

setfillstyle(HATCH_FILL,RED);

floodfill(x_circle,y_circle,border_color);

getch();

closegraph();

}

cs602 2nd assignment 100% correct solution

CS602-2nd-assignment-100%-correct-solution

Cs 602 assignment solution fall 2020
#include<iostream>
#include<conio.h>
#include<graphics.h>
#define round(a) ((int)(a+0.5))
void diplay();
using namespace std;
int j;
float xmini,ymini,xmaxi,ymaxi,arr[20],m;
void cliplft(float x1,float y1, float x2, float y2)
{
if(x2-x1)
{
m=(y2-y1)/(x2-x1);
}
else
m=200000;
if(x1 >= xmini && x2 >=xmini)
{
arr[j]=x2;
arr[j+1]=y2;
j+=2;
}
if(x1 < xmini && x2 >= xmini)
{
arr[j]=xmini;
arr[j+1]=y1+m*(xmini-x1);
arr[j+2]=x2;
arr[j+3]=y2;
j+=4;
}
if(x1 >= xmini && x2 < xmini)
{
arr[j]=xmini;
arr[j+1]=y1+m*(xmini-x1);
j+=2;
}
}
void cliptp(float x1,float y1, float x2, float y2)
{
if(y2-y1)
{
m=(x2-x1)/(y2-y1);
}
else
m=100000;
if(y1 <= ymaxi && y2 <=ymaxi)
{
arr[j]=x2;
arr[j+1]=y2;
j+=2;
}
if(y1 > ymaxi && y2 <= ymaxi)
{
arr[j]=x1+m*(ymaxi-y1);
arr[j+1]=ymaxi;
arr[j+2]=x2;
arr[j+3]=y2;
j+=4;
}
if(y1 <= ymaxi && y2 > ymaxi)
{
arr[j]=x1+m*(ymini-y1);
arr[j+1]=ymaxi;
j+=2;
}
}
void cliprgt(float x1,float y1, float x2, float y2)
{
if(x2-x1)
{
m=(y2-y1)/(x2-x1);
}
else
m=100000;
if(x1 <= xmaxi && x2 <=xmaxi)
{
arr[j]=x2;
arr[j+1]=y2;
j+=2;
}
if(x1 > xmaxi && x2 <= xmaxi)
{
arr[j]=xmaxi;
arr[j+1]=y1+m*(xmaxi-x1);
arr[j+2]=x2;
arr[j+3]=y2;
j+=4;
}
if(x1 <= xmaxi && x2 > xmaxi)
{
arr[j]=xmaxi;
arr[j+1]=y1+m*(xmaxi-x1);
j+=2;
}
}
void clipbtm(float x1,float y1, float x2, float y2)
{
if(y2-y1)
{
m=(x2-x1)/(y2-y1);
}
else
m=200000;
if(y1 >= ymini && y2 >=ymini)
{
arr[j]=x2;
arr[j+1]=y2;
j+=2;
}
if(y1 < ymini && y2 >= ymini)
{
arr[j]=x1+m*(ymini-y1);
arr[j+1]=ymini;
arr[j+2]=x2;
arr[j+3]=y2;
j+=4;
}
if(y1 >= ymini && y2 < ymini)
{
arr[j]=x1+m*(ymini-y1);
arr[j+1]=ymini;
j+=2;
}
}
void display()
{
static int z=0;
for(int xm=0; xm<1; xm++)
{
cout"(x"z",""y"z"): ";
++z;
}
}
int main()
{
int gdriver=DETECT,gmode,n,poly[20],i;
float xi,yi,xf,yf,polyg[20];
xmini=ymini=200;
xmaxi=ymaxi=400;
cout"Windows:-Enter the no. of verices of Ploygon : ";
cin>>n;
cout"Enter the coordinates of points:\n";
for(i=0;i<2*n;i++)
{
if (i==0)
display();
else if(i==2)
display();
else if(i==4)
display();
else if(i==6)
display();
else if(i==8)
display();
else if(i==10)
display();
cin>>polyg[i];
}
polyg[i]=polyg[0];
polyg[i+1]=polyg[1];
for(i=0;i<2*n+2;i++)
{
poly[i]=round(polyg[i]);
}
initgraph(&gdriver,&gmode," ");
setcolor(RED);
rectangle(xmini,ymaxi,xmaxi,ymini);
cout"\t\n \n Press a button to clip a polygon ..";
setcolor(WHITE);
setfillstyle(EMPTY_FILL,WHITE);
fillpoly(n,poly);
getch();
cleardevice();
j=0;
for(i=0;i<2*n;i+=2)
cliplft(polyg[i],polyg[i+1],polyg[i+2],polyg[i+3]);
n=j/2;
for(i=0;i<j;i++)
polyg[i]=arr[i];
polyg[i]=polyg [0];
polyg[i+1]=polyg[1];
j=0;
for(i=0;i<2*n;i+=2)
cliptp(polyg[i],polyg[i+1],polyg[i+2],polyg[i+3]);
n=j/2;
for(i=0;i<j;i++)
polyg[i]=arr[i];
polyg[i]=polyg [0];
polyg[i+1]=polyg[1];
j=0;
for(i=0;i<2*n;i+=2)
cliprgt(polyg[i],polyg[i+1],polyg[i+2],polyg[i+3]);
n=j/2;
for(i=0;i<j;i++)
polyg[i]=arr[i];
polyg[i]=polyg [0];
polyg[i+1]=polyg[1];
j=0;
for(i=0;i<2*n;i+=2)
clipbtm(polyg[i],polyg[i+1],polyg[i+2],polyg[i+3]);
for(i=0;i<j;i++)
poly[i]=round(arr[i]);
if(j)
setcolor(WHITE);
setfillstyle(EMPTY_FILL,WHITE);
fillpoly(j/2,poly);
setcolor(RED);
rectangle(xmini,ymaxi,xmaxi,ymini);
getch();
closegraph();
}

1

2

3

4

## Latest Activity

5 hours ago
Sophie posted a discussion

### Reference letter

14 hours ago
⭐ "Mannat"⭐✔️ liked Black Bird Scientist's discussion graphic designer required
14 hours ago
+ ! zεε liked иαвєєℓ αнмє∂'s discussion CS619 Project Students
19 hours ago
Hamid left a comment for jiya ali
20 hours ago
Hamid and jiya ali are now friends
20 hours ago
Usama shahid joined + M.Tariq Malik's group

### CS604 Operating Systems

yesterday
sria aslam, Khawir Abbas and Sana Shafaq joined Virtual University of Pakistan
yesterday