0% found this document useful (0 votes)
18 views

CS602 Assignment1

The document provides an assignment to draw an ellipse with a given center point and axis lengths using the midpoint ellipse drawing algorithm in C++, display the student ID, and fill the ellipse with color. It includes the C++ code to initialize graphics, calculate ellipse points, draw the ellipse by plotting points, fill it with red, and wait for user input to close the window.

Uploaded by

sonia parveen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

CS602 Assignment1

The document provides an assignment to draw an ellipse with a given center point and axis lengths using the midpoint ellipse drawing algorithm in C++, display the student ID, and fill the ellipse with color. It includes the C++ code to initialize graphics, calculate ellipse points, draw the ellipse by plotting points, fill it with red, and wait for user input to close the window.

Uploaded by

sonia parveen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment No.

01 Total Marks: 20
Semester: Spring 2023
Due Date: 23nd May
CS602: Computer Graphics 2023

Prepared By: https://virtualkitab.com/

https://www.youtube.com/@virtualkitaab
YouTube:

TASK Marks=20

Suppose you are working on a project where you need to draw an ellipse of a given
center point (xc,yc), major axis length (a), and minor axis length (b) using the
Midpoint Ellipse Drawing Algorithm in C++. Write a program to implement the
algorithm and display the resulting ellipse. Then fill the Ellipse with any color and
design using the graphics libraries.

Note: You should display your student ID before displaying the Ellipse.

Solution:
#include <graphics.h>

int main()
{
//initialize graphics window
initwindow(640, 480, "Ellipse Drawing Algorithm");

//set center coordinates and axis lengths


int xc = 320;
int yc = 240;
int a = 100;
int b = 50;

//calculate initial values


int x = 0;
int y = b;
int d = (b * b) - (a * a * b) + (0.25 * a * a);

//display student ID
outtextxy(10, 10, "Student ID: [insert ID here]");

//draw the first quadrant


while ((a * a * (y - 0.5)) > (b * b * (x + 1)))
{
putpixel(xc + x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc - x, yc + y, WHITE);

if (d < 0)
d += (b * b * (2 * x + 3));
else
{
d += ((b * b * (2 * x + 3)) + (a * a * (-2 * y + 2)));
y--;
}
x++;
}

//draw the second quadrant


d = (b * b * (x + 0.5) * (x + 0.5)) + (a * a * (y - 1) * (y - 1)) - (a * a * b * b);
while (y >= 0)
{
putpixel(xc + x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc - x, yc + y, WHITE);

if (d > 0)
d += (a * a * (-2 * y + 3));
else
{
d += ((b * b * (2 * x + 2)) + (a * a * (-2 * y + 3)));
x++;
}
y--;
}

//fill the ellipse with color


setfillstyle(SOLID_FILL, RED);
fillellipse(xc, yc, a, b);

//wait for user to close the window


getch();

//close the graphics window


closegraph();

return 0;
}

You might also like