Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

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

Assignment No. 02
Semester: Fall 2020

CS602: Computer Graphics

Total Marks: 20

Due Date: Dec 17, 2020

 

Objective

The objective of this assignment is to;

§  Learn and practice basic concepts of computer graphics like pixels, lines, text etc using Dev-C++. (You can download Dev-C++ setup from LMS)

§  Learn to clip lines and rigid bodies by using graphics library functions.

§  Learn the concepts of Sutherland and Hodgman's polygon-clipping algorithm.

Instructions:

You have to do the following steps first in order to perform the task.

  1. Install Dev-C++ from your LMS.
  2. Read out the file “Add graphics in Dev cpp” thoroughly and follow the instructions in the file properly provided to you on your LMS.

Please read the following instructions carefully before submitting assignment:

  1. You should consult the recommended books, PowerPoint slides, Handouts and video lectures to clarify your concepts.
  2. You can take any help from your provided labs.
  3. It should be clear that your assignment will not get any credit if:

·       The assignment is submitted after due date.

·       The assignment is copied from Internet or from any other student.

·       The submitted assignment does not open or file is corrupt.

Submission

You are required to submit your solution through LMS in doc file.

You are also required to enter the screenshot of the output of your program.

 

Note: No assignment will be accepted after the due date through email in any case (load shedding, server down, internet malfunctioning etc.).

It is recommended to upload solution file at least two days before its closing date.

For any query about the assignment, contact at cs602@vu.edu.pk

 

TASK                                                                                                               Marks=20

This task is based on the concepts of clipping algorithms, you are required to implement the Sutherland and Hodgman's polygon-clipping algorithm in Dev C++. After executing the program, the program should ask the user to enter the number of vertices of polygon. After entering number of vertices, the program will ask the user to enter coordinates of vertices as shown in the image below:

 

Now the user needs to just press a button, a polygon will be drawn with white color the second press of a button to clip the polygon as shown in the image below:

Views: 884

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

Click on the below link to download the files

CS602_Assignment_No_02_Solution_Fall_2020

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

cs602 2nd assignment 100% correct solution

Click on the below link to download the file

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 radius = 100;

               

                int border_color=WHITE;

                setfillstyle(HATCH_FILL,RED);

                circle(x_circle,y_circle,radius);

                floodfill(x_circle,y_circle,border_color);

               

                getch();

               

                closegraph();

               

               

               

}

 

cs602 2nd assignment 100% correct solution

Click on the below link to download the file

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

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service