Navigation

    Cyberian
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Pro Blog
    • Users
    • Groups
    • Unsolved
    • Solved

    SOLVED CS602 Assignment 2 Solution and Discussion

    CS602 - Computer Graphics
    assignment 1 cs602 solution computer graphics like pixels lines text
    1
    2
    448
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Qanitah Nizam
      Qanitah Nizam last edited by zaasmi

      Re: CS602 Assignment 2 Solution and Discussion Spring 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:
      3. You should consult the recommended books, PowerPoint slides, Handouts and video lectures to clarify your concepts.
      4. You can take any help from your provided labs.
      5. 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 [email protected]

      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:

      1 Reply Last reply Reply Quote 0
      • zaasmi
        zaasmi Cyberian's Gold last edited by

        Solution:

        Program:-
        #include<stdio.h>
        #include<graphics.h>
        #include<conio.h>
        #include<stdlib.h>
        int main()
        {
         	int gd,gm,n,*x,i,k=0;
        	//window coordinates int wx1=220,wy1=140,wx2=420,wy2=140,wx3=420,wy3=340,wx4=220,wy4=340;
        	int w[]={220,140,420,140,420,340,220,340,220,140};//array for drawing window
        	detectgraph(&gd,&gm); 
        	initgraph(&gd,&gm,"c:\\turboc3\\bgi"); //initializing graphics
        	printf("Window:-");
        	setcolor(RED); //red colored window
        	drawpoly(5,w); //window drawn
        	printf("Enter the no. of vertices of polygon: ");
        	scanf("%d",&n);
        	x = malloc(n*2+1);
        	printf("Enter the coordinates of points:\n");
        	k=0;
        	for(i=0;i<n*2;i+=2) //reading vertices of polygon
        	{
        		printf("(x%d,y%d): ",k,k);
        		scanf("%d,%d",&x[i],&x[i+1]);
        		k++;
        	}
        	x[n*2]=x[0]; //assigning the coordinates of first vertex to last additional vertex for drawpoly method.
        	x[n*2+1]=x[1];
        	setcolor(WHITE);
        	drawpoly(n+1,x);
        	printf("\nPress a button to clip a polygon..");
        	getch();
         	setcolor(RED);
         	drawpoly(5,w);
         	setfillstyle(SOLID_FILL,BLACK);
         	floodfill(2,2,RED);
         	gotoxy(1,1); //bringing cursor at starting position
         	printf("\nThis is the clipped polygon..");
         	getch();
        
         	cleardevice();
         	closegraph();
         	return 0;
        }
        
        

        Discussion is right way to get Solution of the every assignment, Quiz and GDB.
        We are always here to discuss and Guideline, Please Don't visit Cyberian only for Solution.
        Cyberian Team always happy to facilitate to provide the idea solution. Please don't hesitate to contact us!
        NOTE: Don't copy or replicating idea solutions.
        Quiz Copy Solution
        Mid and Final Past Papers
        Live Chat

        1 Reply Last reply Reply Quote 0
        • zaasmi
          zaasmi Cyberian's Gold last edited by

          Solution:

          Program:-
          #include<stdio.h>
          #include<graphics.h>
          #include<conio.h>
          #include<stdlib.h>
          int main()
          {
           	int gd,gm,n,*x,i,k=0;
          	//window coordinates int wx1=220,wy1=140,wx2=420,wy2=140,wx3=420,wy3=340,wx4=220,wy4=340;
          	int w[]={220,140,420,140,420,340,220,340,220,140};//array for drawing window
          	detectgraph(&gd,&gm); 
          	initgraph(&gd,&gm,"c:\\turboc3\\bgi"); //initializing graphics
          	printf("Window:-");
          	setcolor(RED); //red colored window
          	drawpoly(5,w); //window drawn
          	printf("Enter the no. of vertices of polygon: ");
          	scanf("%d",&n);
          	x = malloc(n*2+1);
          	printf("Enter the coordinates of points:\n");
          	k=0;
          	for(i=0;i<n*2;i+=2) //reading vertices of polygon
          	{
          		printf("(x%d,y%d): ",k,k);
          		scanf("%d,%d",&x[i],&x[i+1]);
          		k++;
          	}
          	x[n*2]=x[0]; //assigning the coordinates of first vertex to last additional vertex for drawpoly method.
          	x[n*2+1]=x[1];
          	setcolor(WHITE);
          	drawpoly(n+1,x);
          	printf("\nPress a button to clip a polygon..");
          	getch();
           	setcolor(RED);
           	drawpoly(5,w);
           	setfillstyle(SOLID_FILL,BLACK);
           	floodfill(2,2,RED);
           	gotoxy(1,1); //bringing cursor at starting position
           	printf("\nThis is the clipped polygon..");
           	getch();
          
           	cleardevice();
           	closegraph();
           	return 0;
          }
          
          

          Discussion is right way to get Solution of the every assignment, Quiz and GDB.
          We are always here to discuss and Guideline, Please Don't visit Cyberian only for Solution.
          Cyberian Team always happy to facilitate to provide the idea solution. Please don't hesitate to contact us!
          NOTE: Don't copy or replicating idea solutions.
          Quiz Copy Solution
          Mid and Final Past Papers
          Live Chat

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Insaf Sehat Card Live Cricket Streaming

          100% Off on Your FEE Join US! Ask Me How?

          Quiz 100% Result If you want to know how you can join us and get 100% Discount on your FEE ask Cyberian in Chat Room!
          Quiz 100% Result Quiz 100% Result
          solution1255 discussion1206 fall 2019813 assignment 1432 assignment 2297 spring 2020265 gdb 1247 assignment 382 crw10174 spring 201955
          | |
          Copyright © 2021 Cyberian Inc. Pakistan | Contributors
          Live Chat