CS602 Computer Graphics Assignment 2 Solution Fall 2012

Question 1:                                                                                                        [20 Marks]                                                                                                             

 Write a C program that would draw the following shapes; rectangle, ellipse, circle and point in the following way as described below.


Draw the rectangle as described in the figure below and the ellipse, circle and point should be drawn within the rectangle body.

Hint: Use the rectangle(x,y,a,b) function to draw the rectangle.



Ellipse should be enclosed by the rectangle as described in the figure below.

Hint :Use the ellipse(x,y,startangle, endangle, semimajor, semiminor) function to draw the ellipse.



Circle should be drawn with in the ellipse as described in the figure below.

Hint: Use the circle(x,y,radius) function to draw the circle.



Ellipse and circle should have common center and that center point should be displayed as a point.

Hint: Use the putpixel(x,y,colour) function to draw the point.                    

You can choose any colour for drawing rectangle, ellipse, circle and point; it can be of your own choice.                                                                                                         (Expected Output)


You can consult handouts of lecture 13 for help. You have to use Borlandc to run this program as graphics.h is a borlnadc library. You can download borlandc setup from download section of cs602. After installing Borlandc run BC.EXE.


Now Go to Options =>Linker =>Libraries

Press Alt + G

Press Alt +K


It will enable the graphics library. Now change following command in your program according to yourinstallation.

initgraph(&gdriver, &gmode, “c:\tc\bgi”);

For example:

initgraph(&gdriver, &gmode, “c:\BorlandC\bgi”);


If your program still not showing output then just concentrate on logic and submit your assignment. Submit .c files only. You can send email at cs602@vu.edu.pk for any assignment related problem. Your work must be original. No marks will be given in case of cheating or copying from the internet, handouts or from any other student and strict action will be taken against that student.


Your assignment must be uploaded/submitted on or before November 26, 2012


int gd = DETECT,gm,
// for rectangle
// for ellipse, circle and point 
x= 300,y=150,radius=50; 
// change this command as mentioned in the assignment 
initgraph(&gd, &gm, "C:\TC\BGI"); 

rectangle(left, top, right, bottom); 
circle(x, y, radius); 
ellipse(x, y , 0, 360, 100, 50); 
putpixel (x, y, WHITE) 
return 0; 

These are not the correct dimensions you need to change and adjust all shapes