I would like to know how to draw filled polygons using CoreGraphics framework.
Here is example I am trying to draw:
I have A,B,C,D,E,F and G.
Can you suggest me ?
Thanks in advance.
Step 1: Import cv2 and numpy. Step 2: Define the endpoints. Step 3: Define the image using zeros. Step 4: Draw the polygon using the fillpoly() function.
To draw a polygon, start by drawing a circle on a piece of paper using a protractor. Then, decide how many sides you want your polygon to have. Once you've decided, divide 360 by the number of sides to find out what the angle between each set of neighboring lines should be.
To draw or fill a PolygonUse the Graphics methods g. drawPolygon(p) or g. fillPolygon(p) to draw or fill a polygon, where p is the polygon.
- (void)drawRect:(CGRect)rect{
CGContextRef context= UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 0.0, 1.0, 0.0, 1.0);
CGContextSetLineWidth(context, 1.0);
CGContextMoveToPoint(context, 10, 50);
CGContextAddLineToPoint(context, 100, 80);
CGContextAddLineToPoint(context, 120, 120);
CGContextAddLineToPoint(context, 60, 80);
CGContextAddLineToPoint(context, 10, 50);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillPath(context);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With