I want to draw three circles within a pentagon in C++. I also want to give random movement to one of the circles within pentagon. Can anyone tell me the code alongwith the required header files for drawing this.

regards

Recommended Answers

All 9 Replies

depends on the operating system. MS-Windows you might want to use a game engine such as DirectX or OpenGL (both are free).

In fact I am trying to develop a program for my algorithm. Whenever, i try to draw circle using circle(x,y,r) function, my borland c++ compiler gives me error 'BGI graphics not supported'. Tell me how to fix this error?

Regards

How to fix? Use a different compiler that supports BGI graphics. See this link

Or better yet, use win32 api graphics functions. It has a circle() function as well as several others which are similar to Borland's DOS BGI.

which compiler would be the most suitable in this case?

what version of borland compiler do you have? I use Microsoft VC++ 2010 Express which is free.

I have borland C++ 5.02

Use a different compiler and come into the 21st century. That compiler can not be used to access win32 api drawing functions.

thanks! I Changed the compiler!!!

Info:
If using MSCVisual studio w/ win32 project...
Use the Ellipse function to draw a circle

Ex. Ellipse(hDC,100,100,200,200);

Parameters are: hDC, left, top, right, bottom -----------

For a multi-sided shape polygon like a Pentagon use the Polygon function, and the coordinate points for your shape are stored in an array and used by the function.

// Declare Array w/ shape coordinates
POINT Pt[7];
Pt[0].x = 20;
Pt[0].y = 50;
Pt[1].x = 180;
Pt[1].y = 50;

// Function Call to Draw Shape
Ex. Polygon(hDC, Pt, 2);


------------------------------- BELOW IS FUNCTION TO DRAW EQUILATERAL TRIANGLE

// DRAW EQUILATERAL TRIANGLE

//FUNCTION CALL EMAPLE: eqTriangle(hDC,200,200,300,200); 
void eqTriangle(HDC & hDC,double start_x, double start_y, double end_x, double end_y)
{
	double height;
	double side_length;
	double half_length;

	HPEN hPen1;                                                    // Declare Pen
	hPen1 = CreatePen(PS_SOLID,10,RGB(0,0,0));                     // Create Pen
	SelectObject(hDC,hPen1);                                       // Select Pen
	MoveToEx(hDC,start_x,start_y,NULL);                            // Move to First Point
	LineTo(hDC,end_x,end_y);                                       // Draw Bottom of eqTriangle - 

	side_length = end_x - start_x;                                 // Length of Bottom of eqTriangle
	half_length = side_length/2;                                   // Half of Bottom eqTriangle Length
	height = sqrt(pow(side_length,2) - pow(side_length/2,2));      // Height of eqTriangle using Pythagorean Theorem

	LineTo(hDC,start_x + half_length, start_y - height);           // Draw Right Side of eqTriangle
	LineTo(hDC, start_x, start_y);                                 // Draw Left Side of eqTriangle

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.