quartz2d Drawing Small Yellow
- (void) DrawRect: (CGRect) rect{//1. ContextCgcontextref CTX = Uigraphicsgetcurrentcontext ();//2. BodyDrawbody (CTX, rect);//3. Mouth (smile)Drawmouth (CTX, rect);//4. Draw Your eyesDraweyes (CTX, rect);}/** * * eyes * *voidDraweyes (Cgcontextref CTX,CGRectRect) {//1. Black Strap CGFloatStartX = rect. Size. Width*0.5-Radius;CGFloatStarty = topy; Cgcontextmovetopoint (CTX, StartX, starty);CGFloatEndX = StartX +2* Radius;CGFloatEndY = Starty; Cgcontextaddlinetopoint (CTX, EndX, EndY); Cgcontextsetlinewidth (CTX, the); [[UicolorBlackcolor] set];//Draw linesCgcontextstrokepath (CTX);//2. Frame with the most outer ring[Zlcolor ( A, +, the) set];CGFloatKuangradius = Radius *0.4;CGFloatKuangy = Starty;CGFloatKUANGX = rect. Size. Width*0.5-Kuangradius; Cgcontextaddarc (CTX, Kuangx, Kuangy, Kuangradius,0, M_PI *2,0); Cgcontextfillpath (CTX); [Zlcolor ( A, +, the) set];CGFloatKUANGRADIUS1 = Radius *0.4;CGFloatkuangY1 = Starty;CGFloatkuangX1 = rect. Size. Width*0.5+ Kuangradius; Cgcontextaddarc (CTX, kuangX1, kuangY1, KuangRadius1,0, M_PI *2,0); Cgcontextfillpath (CTX);//3. Inside the White box[[UicolorWhitecolor] set];CGFloatWhiteradius = Kuangradius *0.7;CGFloatWhitex = KUANGX;CGFloatWhitey = Kuangy; Cgcontextaddarc (CTX, Whitex, Whitey, Whiteradius,0, M_PI *2,0); Cgcontextfillpath (CTX); [[UicolorWhitecolor] set];CGFloatWHITERADIUS1 = Kuangradius *0.7;CGFloatWhiteX1 = kuangx+2*kuangradius;CGFloatwhiteY1 = kuangy; Cgcontextaddarc (CTX, whiteX1, whiteY1, WhiteRadius1,0, M_PI *2,0); Cgcontextfillpath (CTX);//4. Brown Eyeball[Zlcolor ( the, at, -) set];CGFloatBrownradius = Kuangradius *0.4;CGFloatBrownx = kuangx+2*kuangradius-6;CGFloatBrowny = kuangy; Cgcontextaddarc (CTX, Brownx, Browny, Brownradius,0, m_pi*2,0); Cgcontextfillpath (CTX); [Zlcolor ( the, at, -) set];CGFloatBROWNRADIUS1 = Kuangradius *0.4;CGFloatBrownX1 = kuangx+6;CGFloatbrownY1 = kuangy; Cgcontextaddarc (CTX, brownX1, brownY1, BrownRadius1,0, m_pi*2,0); Cgcontextfillpath (CTX);//5. Black pupil[[UicolorBlackcolor] set];CGFloatBlackradius = Kuangradius *0.2;CGFloatBlackx = kuangx+2*kuangradius-6;CGFloatBlacky = kuangy; Cgcontextaddarc (CTX, Blackx, Blacky, Blackradius,0, m_pi*2,0); Cgcontextfillpath (CTX); [[UicolorBlackcolor] set];CGFloatBLACKRADIUS1 = Kuangradius *0.2;CGFloatBlackX1 = kuangx+6;CGFloatblackY1 = kuangy; Cgcontextaddarc (CTX, blackX1, blackY1, BlackRadius1,0, m_pi*2,0); Cgcontextfillpath (CTX);//6. White Reflective[[UicolorWhitecolor] set];CGFloatLightradius = Kuangradius *0.1;CGFloatLIGHTX = kuangx+2*kuangradius;CGFloatLighty = kuangy; Cgcontextaddarc (CTX, LIGHTX, Lighty, Lightradius,0, m_pi*2,0); Cgcontextfillpath (CTX); [[UicolorWhitecolor] set];CGFloatLIGHTRADIUS1 = Kuangradius *0.1;CGFloatLightX1 = kuangx+2*kuangradius- $;CGFloatlightY1 = kuangy; Cgcontextaddarc (CTX, lightX1, lightY1, LightRadius1,0, m_pi*2,0); Cgcontextfillpath (CTX);}/** * * Draw your mouth * *voidDrawmouth (Cgcontextref CTX,CGRectRect) {//Middle Control point CGFloatCONTROLX = rect. Size. Width*0.5;CGFloatControly = rect. Size. Height*0.4;//Current point CGFloatMarginx = -;CGFloatMarginy =Ten;CGFloatCurrentX = Controlx-marginx;CGFloatCurrentY = Controly-marginy; Cgcontextmovetopoint (CTX, CurrentX, currenty);//End point CGFloatEndX = Controlx + Marginx;CGFloatEndY = CurrentY;//Bezier curveCgcontextaddquadcurvetopoint (CTX, Controlx, Controly, EndX, EndY);//Set color[[UicolorBlackcolor] set];//RenderingCgcontextstrokepath (CTX);}/** * Painting the body * *voidDrawbody (Cgcontextref CTX,CGRectRect) {//Upper semicircle CGFloatTopX = rect. Size. Width*0.5;CGFloatTopy = topy;CGFloatTopradius = Radius; Cgcontextaddarc (CTX, TopX, Topy, Topradius,0, M_PI,1);//Down extension CGFloatMiddlex = Topx-topradius;CGFloatMiddleh = -;//height of the middle body CGFloatMiddley = topy + Middleh; Cgcontextaddlinetopoint (CTX, Middlex, Middley);//Lower semicircle CGFloatBOTTOMX = TopX;CGFloatbottomy = Middley;CGFloatBottomradius = Topradius; Cgcontextaddarc (CTX, Bottomx, bottomy, Bottomradius, M_PI,0,1);//merge pathCgcontextclosepath (CTX);//Set color[Zlcolor (252,218,0) set];//Draw the previous path using the Fill methodCgcontextfillpath (CTX);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS development-quartz2d Draw small Yellow