Ale*_*one 6 iphone objective-c quartz-graphics graphic uibezierpath
我正在寻找一种使用UIBezierPath以编程方式创建星星,旭日和其他"尖刺"效果的方法.

UIBezierPath *sunbeamsPath = [UIBezierPath bezierPath];
[sunbeamsPath moveToPoint: CGPointMake(x, y)];
Run Code Online (Sandbox Code Playgroud)
是否有任何算法能够以编程方式为形状为sunburst生成点,而不会重叠路径?
我也对如下所示的不规则形状的旭日感兴趣:

我会想象这样的算法会占用一定数量的光线,然后在多个线段中粗略地划分圆圈,并在顺时针方向上为这样的线段生成点.我所描述的算法是否已经存在,或者我必须自己编写一个算法?
谢谢!
我知道这很古老,但我对这个问题的第一部分感到好奇,并且在jrturton的帖子中,我创建了一个自定义的UIView,它从视图的中心生成一个UIBezierPath.甚至动画它旋转奖励积分.结果如下:

我使用的代码在这里:
- (void)drawRect:(CGRect)rect {
CGFloat radius = rect.size.width/2.0f;
[self.fillColor setFill];
[self.strokeColor setStroke];
UIBezierPath *bezierPath = [UIBezierPath bezierPath];
CGPoint centerPoint = CGPointMake(rect.origin.x + radius, rect.origin.y + radius);
CGPoint thisPoint = CGPointMake(centerPoint.x + radius, centerPoint.y);
[bezierPath moveToPoint:centerPoint];
CGFloat thisAngle = 0.0f;
CGFloat sliceDegrees = 360.0f / self.beams / 2.0f;
for (int i = 0; i < self.beams; i++) {
CGFloat x = radius * cosf(DEGREES_TO_RADIANS(thisAngle + sliceDegrees)) + centerPoint.x;
CGFloat y = radius * sinf(DEGREES_TO_RADIANS(thisAngle + sliceDegrees)) + centerPoint.y;
thisPoint = CGPointMake(x, y);
[bezierPath addLineToPoint:thisPoint];
thisAngle += sliceDegrees;
CGFloat x2 = radius * cosf(DEGREES_TO_RADIANS(thisAngle + sliceDegrees)) + centerPoint.x;
CGFloat y2 = radius * sinf(DEGREES_TO_RADIANS(thisAngle + sliceDegrees)) + centerPoint.y;
thisPoint = CGPointMake(x2, y2);
[bezierPath addLineToPoint:thisPoint];
[bezierPath addLineToPoint:centerPoint];
thisAngle += sliceDegrees;
}
[bezierPath closePath];
bezierPath.lineWidth = 1;
[bezierPath fill];
[bezierPath stroke];
Run Code Online (Sandbox Code Playgroud)
}
您可以在此处下载示例项目:
https://github.com/meekapps/Sunburst
| 归档时间: |
|
| 查看次数: |
5749 次 |
| 最近记录: |