フットサルのコートを描いてみる 2010/08/21



Objective-Cです。
フットサルのコートのラインを描いてます。
ペナルティエリアの部分はちょっと手をぬいてます。
iPad向けを意識してます。比率は、一応フットサルの公式ルールブックにある大きさ通りかなと思います。

iPad向けのスポーツの戦略ボードは、有料、無料向けを含めて乱立してますね。
もう乗り遅れてしまった感がありありですが....

コートをコードで描いてるコードです。

/**

*/
UIImage* createField1(int w, int h, UIColor *color)
{

float L_W = 5;
const int OFFSET = 50;
UIImage *retImage;

UIGraphicsBeginImageContext(CGSizeMake(w, h));
CGContextRef context = UIGraphicsGetCurrentContext();

{
CGContextSetShouldAntialias(context, 0);
// アンチエイリアスのためのコード
CGContextSetAllowsAntialiasing(context, true);
CGContextSetShouldAntialias(context, true);
}

CGContextBeginPath(context);

{


{// BOX
{
CGContextSetLineWidth(context,L_W);
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextSetRGBFillColor(context,255,255,255,1);
CGContextSetRGBStrokeColor(context,255,255,255,1);
}

CGContextMoveToPoint(context, 0 + OFFSET, h - OFFSET);
CGContextAddLineToPoint(context, 0 + OFFSET, 0 + OFFSET);
CGContextAddLineToPoint(context, w - OFFSET, 0 + OFFSET);
CGContextAddLineToPoint(context, w - OFFSET, h - OFFSET);
CGContextClosePath(context);
CGContextStrokePath(context);

// center line
CGContextMoveToPoint(context, w / 2, 0 + OFFSET);
CGContextAddLineToPoint(context, w / 2, h - OFFSET);
CGContextStrokePath(context);
}



{// center circle
{
CGContextSetLineWidth(context,L_W);
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextSetRGBFillColor(context,255,255,255,1);
CGContextSetRGBStrokeColor(context,255,255,255,1);
}


CGContextAddArc(context, w/2, h/2, (28*3), radians(0), radians(360), 0); // 円弧
//CGContextAddArc(context, 45, 200, 36, radians(25), radians(65), 1); // 円に近いもの
CGContextStrokePath(context);

{ // point
CGContextAddArc(context, w/2, h/2, L_W, M_PI*2.0, 0.0, 0);
//CGContextAddRect(context, CGRectMake(0, 0, d, d));
CGContextDrawPath(context, kCGPathFill);
}
}
{// left(up)

{// penalty area


CGContextAddArc(context, 0 + OFFSET, 342, (28*6), radians(-90), radians(0), 0); // 円弧
CGContextStrokePath(context);
CGContextAddArc(context, 0 + OFFSET, 426, (28*6), radians(90), radians(0), 1); // 円弧
CGContextMoveToPoint(context, (28*6) + OFFSET, 342);
CGContextAddLineToPoint(context, (28*6) + OFFSET, 426);
CGContextStrokePath(context);
}

{//goal
CGContextMoveToPoint(context, 0 + OFFSET, 342);
CGContextAddLineToPoint(context, 0 + (OFFSET - (OFFSET - 5)), 342);
CGContextAddLineToPoint(context, 0 + (OFFSET - (OFFSET - 5)), 426);
CGContextAddLineToPoint(context, 0 + OFFSET, 426);
CGContextStrokePath(context);
}

{ // penalty mark
CGContextAddArc(context, 0 + OFFSET + (28*6), h/2, L_W, M_PI*2.0, 0.0, 0);
//CGContextAddRect(context, CGRectMake(0, 0, d, d));
CGContextDrawPath(context, kCGPathFill);

// second penalty mark
CGContextAddArc(context, 0 + OFFSET + (28*10), h/2, L_W, M_PI*2.0, 0.0, 0);
//CGContextAddRect(context, CGRectMake(0, 0, d, d));
CGContextDrawPath(context, kCGPathFill);
}
}
{// right(down)

{// penalty area


CGContextAddArc(context, w - OFFSET, 342, (28*6), radians(180), radians(-90), 0); // 円弧
CGContextStrokePath(context);
CGContextAddArc(context, w - OFFSET, 426, (28*6), radians(180), radians(90), 1); // 円弧
CGContextMoveToPoint(context, w - ((28*6) + OFFSET), 342);
CGContextAddLineToPoint(context, w - ((28*6) + OFFSET), 426);
CGContextStrokePath(context);
}

{//goal
CGContextMoveToPoint(context, w - OFFSET, 342);
CGContextAddLineToPoint(context, w - (OFFSET - (OFFSET - 5)), 342);
CGContextAddLineToPoint(context, w - (OFFSET - (OFFSET - 5)), 426);
CGContextAddLineToPoint(context, w - OFFSET, 426);
CGContextStrokePath(context);
}

{ // penalty mark
CGContextAddArc(context, w - OFFSET - (28*6), h/2, L_W, M_PI*2.0, 0.0, 0);
//CGContextAddRect(context, CGRectMake(0, 0, d, d));
CGContextDrawPath(context, kCGPathFill);

// second penalty mark
CGContextAddArc(context, w - OFFSET - (28*10), h/2, L_W, M_PI*2.0, 0.0, 0);
//CGContextAddRect(context, CGRectMake(0, 0, d, d));
CGContextDrawPath(context, kCGPathFill);
}
}


}

retImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

[retImage autorelease];
[retImage retain];

return retImage;

}

: