LoginSignup
16
17

More than 5 years have passed since last update.

東京五輪エンブレム for Android

Last updated at Posted at 2015-08-06

瞬発力で作ってみました

olympic.png

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));
    }
}
16
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
17