This assignment creates a drawing program, where you touch the screen, and a wave will ripple away from where you touched.
First, create a new Android Project called Ripples. Use the package edu.centenary.USERNAME.drawtouch and select Android SDK version 17.
Copy the following MainActivity.java file into the package you created under the src directory. This is the controller which runs the application.
Copy the icon ic_launcher.png file into the res/drawable-hdpi directory. This is the icon for your application.
To complete this project, you will need to make a Wave
class that has the following structure:
First, import the library for android.graphics.RectF
. This is how Android
represents a rectangle for drawing objects to the screen. It has floats as data members for the
left, top, right, and bottom boundaries.
You will need three double data members, one to keep track of the x coordinate of the center of the wave, one to track the y coordinate of the center, and one to track the energy of the wave.
You will also need three constants, one integer for the maximum energy of the wave, called MAXENG, set equal to 200, one integer for the minimum energy of a wave, called MINENG, set equal to 10, and one double for the decay rate of the wave, called DECAY, set equal to 0.99.
public Wave(double x, double y)
The constructor brings in the initial center of the circle. The initial energy should be set initially to MAXENG.
public boolean update()
Update will decay the energy of the wave according to the DECAY constant. Each time update is called, energy will be multiplied times the DECAY constant. If after this multiplication the energy is below MINENG, return true, otherwise return false.
public double getRadius()
Returns the radius of the circle, which is MAXENG minus the current energy.
public RectF getBoundingBox()
Calculates the Bounding Box for this wave, a rectangle that completely contains this circle as tightly as possible. This should return a RectF using the constructor that takes four floats, denoting the left, top, right and bottom boundaries for this rectangle.