OOD – Cell Mitosis w/StdDraw

You have already written an ADT, Cell_YI with the instance fields, the attributes which identify all the different components in a cell. In this assignment, you will add a new feature, the draw methods using StdDraw.

Before you get started, think about how you are going to break up the images to show the different phases of the mitosis.

Here are some of the resources you can use for the Cell Mitosis and other animations/simulations: 3 Options:
-Take a cell image and using an image editor make the components of the cell separate images.


-Using multiple images and compile them into an array of “frames”

/*************************************************************************
 *  Compilation:  javac Duke.java
 *  Execution:    java Duke
 *  Dependencies: StdDraw.java StdIn.java
 *
 *  Copyright © 2000–2010, Robert Sedgewick and Kevin Wayne.
 *  Last updated: Wed Feb 9 09:02:07 EST 2011.
 *
 *
 *  Draw the sequence of images T1.gif to T17.gif. This creates
 *  the illusion of motion, where the Java mascot Duke cart-wheels
 *  across the screen.
 *
 *  Reference: http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html#TumbleItem
 *
 *************************************************************************/

public class Duke {

    public static void main(String[] args) {
        int images = 17;                        // number of images
        int WIDTH = 130, HEIGHT = 80;           // images are 130-by-80
        StdDraw.setCanvasSize(WIDTH, HEIGHT);
        StdDraw.setXscale(0, WIDTH);
        StdDraw.setYscale(0, HEIGHT);

        // main animation loop
        for (int t = 0; true; t++) {
            int i = 1 + (t % images);
            String filename = "T" + i + ".gif";  // name of the ith image
            StdDraw.picture(WIDTH/2.0, HEIGHT/2.0, filename);
            StdDraw.show();
            StdDraw.pause(100);
        }
    }

}


-Make your own images by drawing them with an app like the one attached. This will allow you to manipulate the individual components of the cell easier and it will have a fluent transformation. It will look pixelated but that is not a bad thing at all.
https://www.piskelapp.com/


If you need to scale pictures, you can use this method from StdDraw:

/**
 Draws the specified image centered at (x, y),
 rescaled to the specified bounding box.
 The supported image formats are JPEG, PNG, and GIF.

 @param x the center x-coordinate of the image
 @param y the center y-coordinate of the image
 @param filename the name of the image/picture, e.g., "ball.gif"
 @param scaledWidth the width of the scaled image (in screen coordinates)
 @param scaledHeight the height of the scaled image (in screen coordinates)
 @throws IllegalArgumentException if either {@code scaledWidth}
 or {@code scaledHeight} is negative
 @throws IllegalArgumentException if the image filename is invalid
*/
public static void picture(double x, double y, String filename, 
double scaledWidth, double scaledHeight)

/******************************************************************************
 *  Compilation:  javac BouncingBallDeluxe.java
 *  Execution:    java BouncingBallDeluxe
 *  Dependencies: StdDraw.java StdAudio.java
 *                https://introcs.cs.princeton.edu/java/15inout/TennisBall.png
 *                https://introcs.cs.princeton.edu/java/15inout/pipebang.wav
 *
 *  Implementation of a bouncing tennis ball in the box from (-1, -1) to (1, 1),
 *  with sound effects.
 *
 *  % java BouncingBallDeluxe
 *
 ******************************************************************************/

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

        // initial values
        double rx = 0.480, ry = 0.860;     // position
        double vx = 0.015, vy = 0.023;     // velocity
        double radius = 0.05;              // radius

        // set the scale of the coordinate system
        StdDraw.setXscale(-1.0, 1.0);
        StdDraw.setYscale(-1.0, 1.0);
        StdDraw.enableDoubleBuffering();

        // main animation loop
        while (true) { 

            // bounce off wall according to law of elastic collision
            if (Math.abs(rx + vx) + radius > 1.0) {
                vx = -vx;
                
            }
            if (Math.abs(ry + vy) + radius > 1.0) {
                vy = -vy;
                
            }

            // update position
            rx = rx + vx; 
            ry = ry + vy; 

            // set the background to light gray
            StdDraw.clear(StdDraw.LIGHT_GRAY);

            // draw ball on the screen
            StdDraw.picture(rx, ry, "TennisBall.png");

            // display and pause for 20ms
            StdDraw.show();
            StdDraw.pause(20); 
        } 
    } 
} 



/**
 * Turning a functional program to an ADT application.
 * 
 * @GE
 * @java 1.8 date: 1/18/19
 */
public class Ball
{
    private double rx = 0.480, ry = 0.860;     // position
    private double vx = 0.015, vy = 0.023;     // velocity
    private double radius = 0.05;   

    public double rx()
    {
        return rx;
    }

    public double ry()
    {
        return ry;
    }

    public void setRx(double rx)
    {
        this.rx = rx;
    }

    public void setRy(double ry)
    {
        this.ry = ry;
    }

    public double[] getVel()
    {
        double [] vel = { vx, vy};
        return vel;
    }

    public void setVx(double vx)
    {
        this.vx = vx;
    }

    public void setVy(double vy)
    {
        this.vy = vy;
    }

    public double radius()
    {
        return radius;
    }
}

/******************************************************************************
 *
 *  Implementation of a bouncing tennis ball in the box from (-1, -1) to (1, 1),
 *  with sound effects.
 *
 *  % java BouncingBallODD
 *
 ******************************************************************************/

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

        Ball bouncy = new Ball();
        

        // set the scale of the coordinate system
        StdDraw.setXscale(-1.0, 1.0);
        StdDraw.setYscale(-1.0, 1.0);
        StdDraw.enableDoubleBuffering();

        // main animation loop
        while (true) { 

            // bounce off wall according to law of elastic collision
            if (Math.abs(bouncy.rx() + bouncy.getVel()[0]) + bouncy.radius() > 1.0) {
                bouncy.setVx(-bouncy.getVel()[0]);
                
            }
            if (Math.abs(bouncy.ry() + bouncy.getVel()[1]) + bouncy.radius() > 1.0) {
                bouncy.setVy(-bouncy.getVel()[1]);
                
            }

            // update position
            bouncy.setRx(bouncy.rx() + bouncy.getVel()[0]); 
            bouncy.setRy(bouncy.ry() + bouncy.getVel()[1]); 

            // set the background to light gray
            StdDraw.clear(StdDraw.LIGHT_GRAY);

            // draw ball on the screen
            StdDraw.picture(bouncy.rx(), bouncy.ry(), "TennisBall.png");

            // display and pause for 20ms
            StdDraw.show();
            StdDraw.pause(20); 
        } 
    } 
}