0% found this document useful (0 votes)
4 views3 pages

Edit

The document contains a C++ program designed to draw a pattern using DDA line and Bresenham's circle drawing algorithms, encapsulated within a class called ShapeDrawer. The program prompts the user for the center coordinates and radius, then draws a circle and a triangle pattern. It includes necessary graphics library functions and demonstrates basic object-oriented programming concepts.

Uploaded by

gaurav274chavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Edit

The document contains a C++ program designed to draw a pattern using DDA line and Bresenham's circle drawing algorithms, encapsulated within a class called ShapeDrawer. The program prompts the user for the center coordinates and radius, then draws a circle and a triangle pattern. It includes necessary graphics library functions and demonstrates basic object-oriented programming concepts.

Uploaded by

gaurav274chavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Computer Engineering

SE D 2024-25
CG Lab Practical

8. Write C++ program to draw the following


pattern. Use DDA line and Bresenham‘s circle
drawing algorithm. Apply the concept of
encapsulation.

Code:

#include <graphics.h>
#include <iostream> #include
<math.h>
using namespace std;

class ShapeDrawer { public:


void drawLine(int x1, int y1, int x2, int y2) {
int dx = x2 - x1; int dy = y2 - y1;
int steps = std::max(abs(dx), abs(dy));

float xInc = dx / (float)steps;


float yInc = dy / (float)steps;

float x = x1;
float y = y1;

for (int i = 0; i <= steps; i++) {


putpixel(round(x), round(y), WHITE);
x += xInc;
y += yInc;
}
}

void drawCircle(int xc, int yc, int r) {


int x = 0, y = r;
int d = 3 - 2 * r;

while (y >= x) {

Name: Binay Tilokchandani S11_27 1


Department of Computer Engineering
SE D 2024-25
CG Lab Practical

putpixel(xc + x, yc + y, WHITE);
putpixel(xc - x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc - x, yc - y, WHITE); putpixel(xc
+ y, yc + x, WHITE); putpixel(xc - y, yc + x,
WHITE); putpixel(xc + y, yc - x, WHITE);
putpixel(xc - y, yc - x, WHITE);
x++;

if (d > 0) {
y--;
d = d + 4 * (x - y) + 10;
} else {
d = d + 4 * x + 6;
}
}
}

void drawPattern(int xc, int yc, int r)


{ drawCircle(xc, yc, r);

int x1 = xc, y1 = yc - r;
int x2 = xc - r * sqrt(3) / 2, y2 = yc + r / 2;
int x3 = xc + r * sqrt(3) / 2, y3 = yc + r / 2;

drawLine(x1, y1, x2, y2);


drawLine(x2, y2, x3, y3); drawLine(x3,
y3, x1, y1);

drawCircle(xc, yc, r / 2);


}
};

int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, (char*)"");
ShapeDrawer drawer;
int xc,yc,r;
cout<<"Name: Binay Tilokchandani"; cout<<"\
nenter x coordinate of center: ";

Name: Binay Tilokchandani S11_27 2


Department of Computer Engineering
SE D 2024-25
CG Lab Practical

cin>>xc;
cout<<"enter y coordinate of center: ";
cin>>yc;
cout<<"enter radius: ";
cin>>r;
drawer.drawPattern(xc, yc, r);
getch(); closegraph();
return 0;
}

OUTPU
T

Date: Ms. Yatri Davda

Name: Binay Tilokchandani S11_27 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy