Created
March 4, 2016 06:52
-
-
Save ajonnet/6fc0cf6e66684f4a54a9 to your computer and use it in GitHub Desktop.
Function to print circle of Asterisk in Objective C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) asteriskCircleWidthRadius:(CGFloat)rad filled:(BOOL) fill border:(NSUInteger) borderW{ | |
borderW -= 1; | |
CGFloat dia = (rad + borderW) * 2; | |
CGFloat centerX,centerY; | |
centerX = centerY = dia/2.0; //-1 for | |
NSMutableString *op = [NSMutableString string]; | |
NSMutableString *opCircle = [NSMutableString string]; | |
[op appendString:@"\n"]; | |
[opCircle appendString:@"\n"]; | |
for (NSUInteger x = 0; x<=dia; x++) { | |
for (NSUInteger y = 0; y<=dia; y++) { | |
double dis = sqrt((x-centerX)*(x-centerX) + (y-centerY)*(y-centerY)); | |
[op appendFormat:@"%5.02f ",dis]; | |
CGFloat tolerance = borderW + 0.4; | |
if ((dis >= (rad - tolerance) || fill) && (dis <= (rad + tolerance))) { | |
[opCircle appendString:@"* "]; | |
}else { | |
[opCircle appendString:@" "]; | |
} | |
} | |
[op appendString:@"\n"]; | |
[opCircle appendString:@"\n"]; | |
} | |
//NSLog(@"%@",op); | |
NSLog(@"%@",opCircle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output