2

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.

MegaManX
  • 8,766
  • 12
  • 51
  • 83

1 Answers1

0

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.

Emir Akaydın
  • 5,708
  • 1
  • 29
  • 57
  • They have same staring points (50, 50), but radii are different (100, 128) and (128, 128). – MegaManX Dec 12 '11 at 14:18
  • Then you should slide the stating points a little bit. and use the perfect circle shape instead of ellipse. (100, 100) instead of (128, 128) for example. – Emir Akaydın Dec 12 '11 at 14:20
  • I don't need perfect circles. I want to draw a circle, and than clip ellipse shaped area from it. First paragraph draws circle (that works), second should clip ellipse from it, but it's not working as expected. How can i solve this? – MegaManX Dec 12 '11 at 14:31