简体   繁体   中英

iPhone How to clip crescent moon pattern

With help from stack overflow i am getting familiar with quartz drawing in iPhone. I want to make code that clips crescent moon pattern, this what i have so far, but its not working quite as i expect:

contextRef = UIGraphicsGetCurrentContext();
CGContextSaveGState(contextRef);
onlyDrawTopHalf = YES;
halfMultiplier = onlyDrawTopHalf ? -1.0 : 1.0;
ellipse = CGRectMake(50, 50, 128, 128);
clipRect = CGRectOffset(ellipse, halfMultiplier * ellipse.size.width / 2, 0);
CGContextClipToRect(contextRef, clipRect);
CGContextRestoreGState(contextRef);


onlyDrawTopHalf = YES;
halfMultiplier = onlyDrawTopHalf ? -1.0 : 1.0;
ellipse = CGRectMake(50, 50, 100, 128);
clipRect = CGRectOffset(ellipse, halfMultiplier * ellipse.size.width / 2, 0);
CGContextAddEllipseInRect(contextRef, clipRect);
CGContextEOClip(contextRef);
CGContextFillEllipseInRect(contextRef, ellipse);

To be precise, first paragraph of code draws circle (this works), second one should clip ellipse from it, but this is not working as intended.

Both shapes need to be perfect circles, not ellipses. Second circles' radius should be a little smaller and it should be a little bir shifted to the right (or left) to get the perfect crescent effect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM