cgpath

How to create a perfect half circle with CGPathAddCurveToPoint?

◇◆丶佛笑我妖孽 提交于 2019-12-04 14:35:47
I am trying to create a perfect right half circle of 15 points radius with CGPathAddCurveToPoint, like this: CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddCurveToPoint(path, NULL, 15, 0, 15, 30, 0, 30); It starts at the top middle of the circle. Then the first control point is set to the top right corner of the circle's bounding box. The second control point is set to the bottom right corner of the circle's bounding box. The circle ends at bottom middle of the bounding box. But when drawn, the circle has an egg-like shape. How can I make a perfect, flawless right semisphere starting at point 0

Extract path information from an black&white bitmap image

不打扰是莪最后的温柔 提交于 2019-12-04 14:05:54
问题 It is not easy to draw a shape with Quartz 2D to depict an image as following. Is it possible to extract a CGPathRef information from a black&white bitmap image? The white part is actually transparent. Edit : What I want to achieve: I want to set the physicsBody of a SKSpriteNode with the same shape of the image bottle.png SKSpriteNode * myBottle = [SKSpriteNode spriteNodeWithImageNamed:@"bottle"]; . . . myBottle.physicsBody = [SKPhysicsBody bodyWithEdgeChainFromPath:path]; Her path is a

How to get the path Quartz is using to stroke a NSBezierPath

主宰稳场 提交于 2019-12-04 12:41:28
I'm using this code to stroke a NSBezierPath with a wide, dashed, black line. ( c and strForBezier are defined somewhere else) NSGlyph glyph; for(n = 0; n < len; n++) { glyph = [font glyphWithName: [strForBezier substringWithRange:NSMakeRange(n, 1)]]; [path appendBezierPathWithGlyph: glyph inFont: font]; } CGFloat pattern2[4]; pattern2[0]=5*c; pattern2[1]=2*c; pattern2[2]=2*c; pattern2[3]=2*c; [path setLineDash:pattern2 count:4 phase:0]; [path setLineWidth:c]; [path stroke]; [[NSColor blueColor] set ]; [path fill]; How can I get the black NSBezierPath ? I'm making the assumption that a

How to draw a filled path/shape in different colors

时光总嘲笑我的痴心妄想 提交于 2019-12-04 12:36:28
I need to color a shape on my screen any color I wish. I am currently trying to do this with a UIImage which I want to recolor to my desires. The only way to do this, as far as I know, is to take the individual pixels of the UIImage, which calls for many more lines of code that I would like to write to fix this problem. Is there any way to change the UIImage color other than what I have written? Would it be easier to draw the shape in context and fill it? TY. Update: The Hexagon is drawing itself the right way, but it doesn't fill right at all. Here is the code: self.Hexagon.lineWidth=10;

How to animate a human written stroke using Swift/iOS?

强颜欢笑 提交于 2019-12-04 07:33:25
问题 Objective I am attempting to create an animated approximation of human writing, using a UIBezierPath generated from a glyph. I understand and I have read the many UIBezierPath questions which sound similar to mine (but are not the same). My goal is to create an animation that approximates the look of a human performing the writing of characters and letters. Background I've created a playground that I am using to better understand paths for use in animating glyphs as if they were drawn by hand

Repeat SKAction starting position changes

那年仲夏 提交于 2019-12-04 06:34:15
问题 I've got a path and a SKShapeNode and would like to have the SKShapeNode follow the path forever (Hexagon shape). let pathHexagon:SKShapeNode = SKShapeNode() let player:SKShapeNode = SKShapeNode() pathHexagon.path = playerHexagonPath(pathHexRadius) pathHexagon.position = CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame)) pathHexagon.strokeColor = UIColor.blackColor() pathHexagon.lineWidth = 5 addChild(pathHexagon) player.path = playerPath(playerSize) player.position = CGPoint(x:

CGPath from image

僤鯓⒐⒋嵵緔 提交于 2019-12-03 21:51:41
I need to create mask based on image (any possible shape). I need to: Create CALayer with CGPath as a proper mask Call [UIView.layer setMask: with layer above ] So main big question is how to set CGPath based on black-white image? Or is it possible to place mask directly from image? Thanks! Example image of a mask: You will need to create your image with an alpha channel. According to CALayer 's mask property documentation: An optional layer whose alpha channel is used as a mask to select between the layer's background and the result of compositing the layer's contents with its filtered

Resize UIView to fit a CGPath

折月煮酒 提交于 2019-12-03 16:36:27
I have a UIView subclass on which the user can add a random CGPath. The CGPath is added by processing UIPanGestures. I would like to resize the UIView to the minimal rect possible that contains the CGPath. In my UIView subclass, I have overridden sizeThatFits to return the minimal size as such: - (CGSize) sizeThatFits:(CGSize)size { CGRect box = CGPathGetBoundingBox(sigPath); return box.size; } This works as expected and the UIView is resized to the value returned, but the CGPath is also "resized" proportionally resulting in a different path that what the user had originally drawn. As an

Move CGPathCreateMutable() so the path stays the same?

烈酒焚心 提交于 2019-12-03 16:25:35
I have got 9 hexagon sprites across the screen and I have to specify a certain path around them to make their area touchable. I don't want to set the coordinates for every single path respectively, so can't I just use the first path (the hexagons are all the same size) and move its origin to another position (without destroying the shape)? (If i do it now, the CGPathAddLineToPoint(); adds the points of the hexagon from the previous hexagon. I hope I got the idea across ... (see picture... NOTE : The grey octagon on the upper right is the exact same size and shape as the black one)![Move path

Is it possible to play a path backwards in a CAKeyFrameAnimation?

久未见 提交于 2019-12-03 11:29:45
问题 I want to animate the position of a CALayer based on a CGPath, but I want to play it backwards. Is there any way to animate a path backwards, or reverse a CGPath? 回答1: animation.speed = -1; ? 回答2: This may not be the best solution, but it worked for me. I told the animation to autoreverse, then started it halfway in. But to prevent it from animating back again I needed to terminate it early. - (void) animate { CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@