Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw filled polygons?

I would like to know how to draw filled polygons using CoreGraphics framework.

Here is example I am trying to draw:

enter image description here

I have A,B,C,D,E,F and G.

Can you suggest me ?

Thanks in advance.

like image 966
Ferdinand Avatar asked Nov 22 '11 11:11

Ferdinand


People also ask

How do you draw a filled polygon in Opencv?

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.

How do you draw a polygon step by step?

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.

How do you create a filled polygon in Java?

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.


1 Answers

- (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);
}
like image 80
Aravindhan Avatar answered Nov 15 '22 05:11

Aravindhan