I have created a menu that allows users to choose the shape that they wanted to be drawn, then the user click on two points, band the chosen shape will be drawn on that point. I did the triangle this way. But I am not really sure how to draw a star using the same way.
class Triangle : Shape
{
//This class contains the specific details for a triangle defined in terms of opposite corners
Point keyPt, oppPt; // these points identify opposite corners of the triangle
public Triangle(Point keyPt, Point oppPt) // constructor
{
this.keyPt = keyPt;
this.oppPt = oppPt;
}
public void draw(Graphics g, Pen blackPen)
{
double xDiff, yDiff, xMid, yMid; // range and mid points of x & y
// calculate ranges and mid points
xDiff = oppPt.X - keyPt.X;
yDiff = oppPt.Y - keyPt.Y;
xMid = (oppPt.X + keyPt.X) / 2;
yMid = (oppPt.Y + keyPt.Y) / 2;
// draw triangle
g.DrawLine(blackPen, (int)keyPt.X, (int)keyPt.Y, (int)(xMid + yDiff / 2), (int)(yMid - xDiff / 2));
g.DrawLine(blackPen, (int)(xMid + yDiff / 2), (int)(yMid - xDiff / 2), (int)oppPt.X, (int)oppPt.Y);
g.DrawLine(blackPen, (int)keyPt.X, (int)keyPt.Y, oppPt.X, oppPt.Y);
}
}
Appreciate your help.