您应该看一下Apple Documentation 中的QuartzDemo,它有很多绘图示例.
使用此演示,您可以在Polygon演示中将de star(6条边)更改为三角形(3条边).只需更改QuartzPolygons.m循环中的增量数,只需注释"//将星形添加到当前路径".例如,以下是等边三角形的代码:
-(void)drawInContext:(CGContextRef)context
{
// Drawing with a white stroke color
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
// Drawing with a blue fill color
CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0);
CGPoint center;
// Add a triangle to the current path
center = CGPointMake(90.0, 90.0);
CGContextMoveToPoint(context, center.x, center.y + 60.0);
for(int i = 1; i < 3; ++i)
{
CGFloat x = 60.0 * sinf(i * 4.0 * M_PI / 3.0);
CGFloat y = 60.0 * cosf(i * 4.0 * M_PI / 3.0);
CGContextAddLineToPoint(context, center.x + x, center.y + y);
}
// And close the subpath.
CGContextClosePath(context);
// Now draw the triangle with the current drawing mode.
CGContextDrawPath(context, drawingMode);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2491 次 |
| 最近记录: |