package uk.co.barbuzz.beerprogressview;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.v7.widget.helper.ItemTouchHelper;
/* loaded from: classes.dex */
public class Bubble {
    private static final int BUBBLE_SIZE = 20;
    private static final int FPS = 30;
    private static final int SPEED = 30;
    private double amp;
    private double freq;
    private float maxRadius;
    private float radius;
    private double skew;
    private int step;
    private float x;
    private float y;
    public boolean popped = false;
    private Paint paint = new Paint();

    public static int randRange(int min, int max) {
        int mod = max - min;
        double val = Math.ceil(Math.random() * 1000000.0d) % mod;
        return ((int) val) + min;
    }

    public Bubble(int width, int height, int topMargin, int bubbleColour) {
        this.paint.setColor(bubbleColour);
        this.paint.setStyle(Paint.Style.FILL);
        this.paint.setAntiAlias(true);
        recycle(true, width, height, topMargin);
    }

    public void recycle(boolean initial, int width, int height, int topMargin) {
        if (initial) {
            this.y = randRange(topMargin, height);
        } else {
            this.y = (randRange(0, 21) - 10) + height;
        }
        this.x = randRange(0, width);
        this.radius = 1.0f;
        this.maxRadius = randRange(3, 20);
        this.paint.setAlpha(randRange(100, ItemTouchHelper.Callback.DEFAULT_SWIPE_ANIMATION_DURATION));
        this.popped = false;
        this.step = 0;
        this.amp = Math.random() * 3.0d;
        this.freq = Math.random() * 2.0d;
        this.skew = Math.random() - 0.5d;
    }

    public void update(int fps, float angle) {
        double speed = 1.0d * Math.log(this.radius);
        this.y = (float) (this.y - speed);
        double d = this.amp;
        double d2 = this.freq;
        int i = this.step;
        this.step = i + 1;
        this.x = (float) (this.x + (d * Math.sin(d2 * i * speed)) + this.skew);
        if (this.radius < this.maxRadius) {
            this.radius += this.maxRadius / ((fps / 30.0f) * this.radius);
            if (this.radius > this.maxRadius) {
                this.radius = this.maxRadius;
            }
        }
    }

    public boolean popped(int width, int height, int topMargin) {
        return this.y + this.radius <= -20.0f || this.y - this.radius >= ((float) height) || this.x + this.radius <= 0.0f || this.x - this.radius >= ((float) width) || this.y - this.radius <= ((float) topMargin);
    }

    public void draw(Canvas canvas) {
        canvas.drawCircle(this.x, this.y, this.radius, this.paint);
    }
}
