/**
 * Name: Harry Smith
 *
 * PennKey: sharry
 *
 * Description: On a black screen, draw an expanding white circle centered on
 * where I clicked my mouse. Immediately start drawing a new circle whenever I
 * click.
 */

public class BubbleOut {
    public static void main(String[] args) {

        // variables for the bubble:
        // need a (x, y) position for the center and a radius
        double xCenter = 0.0;
        double yCenter = 0.0;
        double radius = 0.0;

        // setup
        PennDraw.setPenColor(PennDraw.WHITE);
        PennDraw.setPenRadius(0.008);
        PennDraw.enableAnimation(24);

        while (true) {
            // Important to clear at the start of every frame to overwrite previous circles
            PennDraw.clear(50, 50, 50);

            // mousePressed == true when user clicks mouse in that frame
            // is the user CURRENTLY clicking?
            if (PennDraw.mousePressed()) {
                xCenter = PennDraw.mouseX(); // gives x coord of the mouse between 0 -> 1
                yCenter = PennDraw.mouseY(); // gives y coord ...
                radius = 0.0;
            }

            // has the user pressed a key?
            if (PennDraw.hasNextKeyTyped()) {
                // if so, store that key press
                char keyPressed = PennDraw.nextKeyTyped();
                if (keyPressed == 'r') {
                    // Math.random() --> double [0, 1)
                    // (Math.random() * 256)--> double [0, 256)
                    // (int) (Math.random() * 256) --> int [0, 255]
                    // colors are ints between [0, 255]
                    int redSignal = (int) (Math.random() * 256);
                    PennDraw.setPenColor(redSignal, 50, 50);
                }
            }

            PennDraw.circle(xCenter, yCenter, radius);
            radius += 0.001; // radius = radius + 0.01;

            // this needs to come after all the things drawn in this frame
            PennDraw.advance();
        }
        // Code never gets here
    }
}