2013-10-30 28 views

回答

4

我有平局钻石Thish代码使用来绘制钻石

INT MGX = penThickness * 6; int mgY = penThickness * 2;

CGPoint st = CGPointMake(MIN(startingPt.x, endingPt.x), MIN(startingPt.y, endingPt.y)); 
    CGPoint et = CGPointMake(MAX(startingPt.x, endingPt.x), MAX(startingPt.y, endingPt.y)); 

    CGRect outsideRect = CGRectMake(st.x,st.y, MAX(mgX, et.x-st.x), MAX(mgY, et.y-st.y)); 
    CGRect insideRect = CGRectInset(outsideRect, outsideRect.size.width * 0.30f, outsideRect.size.height * 0.30f); 

    CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(insideRect), CGRectGetMinY(outsideRect)); 

    //0 line 
    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(insideRect), CGRectGetMinY(outsideRect)); 


    //1 line 
    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(outsideRect), CGRectGetMidY(insideRect)); 

    //2 line 
    CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(insideRect), CGRectGetMaxY(outsideRect)); 


    //3 line 
    CGPathAddLineToPoint(pathRef, nil, CGRectGetMinX(insideRect), CGRectGetMaxY(outsideRect)); 

    //4 line 

    CGPathAddLineToPoint(pathRef, nil, CGRectGetMinX(outsideRect), CGRectGetMidY(insideRect)); 

    CGPathCloseSubpath(pathRef); 
4

我有结束于绘图复合剂在Hexagone的thish代码在拉伸加工Haxagon

INT MGX = penThickness * 6; int mgY = penThickness * 6;

CGPoint st = CGPointMake(MIN(startingPt.x, endingPt.x), MIN(startingPt.y, endingPt.y)); 
CGPoint et = CGPointMake(MAX(startingPt.x, endingPt.x), MAX(startingPt.y, endingPt.y)); 

CGRect outsideRect = CGRectMake(st.x,st.y, MAX(mgX, et.x-st.x), MAX(mgY, et.y-st.y)); 
CGRect insideRect = CGRectInset(outsideRect, outsideRect.size.width * 0.30f, outsideRect.size.height * 0.30f); 

CGPathMoveToPoint(pathRef, nil, CGRectGetMinX(insideRect), CGRectGetMinY(outsideRect)); 

//0 line 
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(insideRect), CGRectGetMinY(outsideRect)); 


//1 line 
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(outsideRect), CGRectGetMidY(insideRect)); 

//2 line 
CGPathAddLineToPoint(pathRef, nil, CGRectGetMaxX(insideRect), CGRectGetMaxY(outsideRect)); 


//3 line 
CGPathAddLineToPoint(pathRef, nil, CGRectGetMinX(insideRect), CGRectGetMaxY(outsideRect)); 

//4 line 

CGPathAddLineToPoint(pathRef, nil, CGRectGetMinX(outsideRect), CGRectGetMidY(insideRect)); 

CGPathCloseSubpath(pathRef);