I am making an application in which a raster image of snow will fall. It takes a random position on the screen and falls to a certain distance. I can make the snow fall a certain distance and disappear. But I need the snow to become blurry at the beginning and gradually appear good and finally appear blurry and disappear during its movement on the screen (means that we know how the snow falls. Similarly, users should easily understand the beginning and end of snow falling). Please help me make the snow move.
import java.util.Random;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.view.animation.TranslateAnimation;
public class Leaf {
private float x;
private float rawX;
private float y;
private float speedY;
private int heightBound;
private Bitmap bitmap;
private float bounceOffset;
private boolean touched;
private float xOffset,yOffset;
private int width;
private int height;
float angle;
float randomx,randomy,randomy1;
public Leaf(Bitmap source, int canvasHeight, int canvasWidth){
Random rand = new Random();
randomx=rand.nextFloat();
randomy1=rand.nextFloat();
speedY = 1 + rand.nextFloat() * 3;
width = (int)(source.getWidth());
height = (int)(source.getHeight());
bitmap = Bitmap.createScaledBitmap(source, width, height, true);
rawX = rand.nextFloat() * canvasWidth;
x = rawX;
randomy=1+rand.nextFloat()*canvasHeight;
y = -bitmap.getHeight();
heightBound = canvasHeight + bitmap.getHeight();
bounceOffset = 8.0f;
touched = false;
xOffset = rand.nextFloat();
if(xOffset >= 1.5){
xOffset = xOffset - 3;}
}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public float getSpeedY() {
return speedY;
}
public void setSpeedY(float speedY) {
this.speedY = speedY;
}
public boolean isTouched(){
return touched;
}
public void setTouched(boolean flag){
this.touched = flag;
}
public Bitmap getBitmap() {
return bitmap;
}
public void setBitmap(Bitmap flag) {
this.bitmap = flag;
}
public void drawLeaf(Canvas canvas, Paint paint){
Matrix matrix = new Matrix();
matrix.reset();
matrix.postTranslate(x+2,randomy+2);
matrix.postRotate(angle);
float px=x+bitmap.getHeight()/2;
float py=y+bitmap.getWidth()/2;
matrix.postTranslate(px, py);
canvas.drawBitmap(bitmap, matrix, paint);
}
public void handleFalling(boolean fallingDown){
if(fallingDown){
this.y += this.speedY;
this.x += this.xOffset;
angle=angle+0.5f;
if(this.y >= (5*randomy1)+(5*bitmap.getHeight())){
this.y = -this.bitmap.getHeight();
this.x = rawX;
}
}else{
this.y -= this.speedY;
this.x += this.xOffset;
angle=angle+0.4f;
if(this.y <= -this.bitmap.getHeight()){
this.y += 6*this.bitmap.getHeight();
this.x = rawX;
}
}
}
public void handleTouched(float touchX, float touchY){
float centerX = this.x + this.bitmap.getWidth() / 2.0f;
float centerY = this.y + this.bitmap.getHeight() / 2.0f;
if(centerX <= touchX){
this.x -= this.bounceOffset;
if(centerY <= touchY){
this.y -= this.bounceOffset;
}else{
this.y += this.bounceOffset;
}
}else{
this.x += this.bounceOffset;
if(centerY <= touchY){
this.y -= this.bounceOffset;
}else{
this.y += this.bounceOffset;
}
}
this.bounceOffset *= 0.9;
if(this.bounceOffset < 1.0){
this.bounceOffset = 8.0f;
touched = false;
}
}
}
Here leaf means snow. This class is designed to create a falldown leaf in the handlefall () method. and drawleaf () is for translating a sheet using a matrix.