瞬発力で作ってみました
TokyoOlympicLogo.java
public class TokyoOlympicLogo extends View {
public TokyoOlympicLogo(Context context) {
super(context);
}
public TokyoOlympicLogo(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TokyoOlympicLogo(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setAntiAlias(true);
RectF rectF;
// 左側のゴールド
paint.setColor(0xffb08e47);
rectF = new RectF(0, 0, getWidth() / 3f, getHeight() / 2f);
canvas.drawRect(rectF, paint);
// 右側のシルバー
paint.setColor(0xffb4b3b4);
rectF = new RectF(getWidth() * 2 / 3f, getHeight() / 2f, getWidth(), getHeight());
canvas.drawRect(rectF, paint);
// 中央の白
paint.setColor(0xffffffff);
canvas.drawCircle(getWidth() / 2f, getHeight() / 2f, getWhiteCircleRadius(), paint);
// 中央のグレー
paint.setColor(0xff363838);
rectF = new RectF(getWidth() / 3f, 0, getWidth() * 2 / 3f, getHeight());
canvas.drawRect(rectF, paint);
// 右上の赤
paint.setColor(0xffd7151a);
canvas.drawCircle(getWidth() * 5 / 6f, getHeight() / 6f, getHeight() / 6f, paint);
}
private float getWhiteCircleRadius() {
float centerX = getWidth() / 2f;
float centerY = getHeight() / 2f;
float x = getWidth() / 3f;
float y = 0;
return (float) Math.sqrt((centerX - x) * (centerX - x) + (centerY - y) * (centerY - y));
}
}