Android Open Source - Coloring-book Particle






From Project

Back to project page Coloring-book.

License

The source code is released under:

Apache License

If you think the Android project Coloring-book listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.plattysoft.leonids;
/*from  w  w  w . j  av a 2s. com*/
import java.util.List;

import com.plattysoft.leonids.modifiers.ParticleModifier;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;

public class Particle {

  protected Bitmap mImage;
  
  public float mCurrentX;
  public float mCurrentY;
  
  public float mScale = 1f;
  public int mAlpha = 255;
  
  public float mInitialRotation = 0f;
  
  public float mRotationSpeed = 0f;
  
  public float mSpeedX = 0f;
  public float mSpeedY = 0f;

  public float mAccelerationX;
  public float mAccelerationY;

  private Matrix mMatrix;
  private Paint mPaint;

  private float mInitialX;
  private float mInitialY;

  private float mRotation;

  private long mTimeToLive;

  protected long mStartingMilisecond;

  private int mBitmapHalfWidth;
  private int mBitmapHalfHeight;

  private List<ParticleModifier> mModifiers;


  protected Particle() {    
    mMatrix = new Matrix();
    mPaint = new Paint();
  }
  
  public Particle (Bitmap bitmap) {
    this();
    mImage = bitmap;
  }

  public void configure(long timeToLive, float emiterX, float emiterY) {
    mBitmapHalfWidth = mImage.getWidth()/2;
    mBitmapHalfHeight = mImage.getHeight()/2;
    
    mInitialX = emiterX - mBitmapHalfWidth;
    mInitialY = emiterY - mBitmapHalfHeight;
    mCurrentX = mInitialX;
    mCurrentY = mInitialY;
    
    mTimeToLive = timeToLive;
    mScale = 1;
    mAlpha = 255;
  }

  public boolean update (long miliseconds) {
    long realMiliseconds = miliseconds - mStartingMilisecond;
    if (realMiliseconds > mTimeToLive) {
      return false;
    }
    mCurrentX = mInitialX+mSpeedX*realMiliseconds+mAccelerationX*realMiliseconds*realMiliseconds;
    mCurrentY = mInitialY+mSpeedY*realMiliseconds+mAccelerationY*realMiliseconds*realMiliseconds;
    mRotation = mInitialRotation + mRotationSpeed*realMiliseconds/1000;
    for (int i=0; i<mModifiers.size(); i++) {
      mModifiers.get(i).apply(this, realMiliseconds);
    }
    return true;
  }
  
  public void draw (Canvas c) {
    mMatrix.reset();
    mMatrix.postRotate(mRotation, mBitmapHalfWidth, mBitmapHalfHeight);
    mMatrix.postScale(mScale, mScale, mBitmapHalfWidth, mBitmapHalfHeight);
    mMatrix.postTranslate(mCurrentX, mCurrentY);
    mPaint.setAlpha(mAlpha);    
    c.drawBitmap(mImage, mMatrix, mPaint);
  }

  public Particle activate(long startingMilisecond, List<ParticleModifier> modifiers) {
    mStartingMilisecond = startingMilisecond;
    // We do store a reference to the list, there is no need to copy, since the modifiers do not carte about states 
    mModifiers = modifiers;
    return this;
  }
}




Java Source Code List

com.kidsgames.gamebase.DrawerActivity.java
com.kidsgames.gamebase.DrawingView.java
com.kidsgames.menu.DrawerSliderActivity.java
com.kidsgames.menu.FixedSpeedScroller.java
com.kidsgames.menu.FixedSpeedViewPager.java
com.kidsgames.menu.MainMenu.java
com.kidsgames.menu.SlideAdapter.java
com.kidsgames.utils.ResourceId.java
com.plattysoft.leonids.AnimatedParticle.java
com.plattysoft.leonids.ParticleField.java
com.plattysoft.leonids.ParticleSystem.java
com.plattysoft.leonids.Particle.java
com.plattysoft.leonids.initializers.AccelerationInitializer.java
com.plattysoft.leonids.initializers.ParticleInitializer.java
com.plattysoft.leonids.initializers.RotationInitiazer.java
com.plattysoft.leonids.initializers.RotationSpeedInitializer.java
com.plattysoft.leonids.initializers.ScaleInitializer.java
com.plattysoft.leonids.initializers.SpeeddByComponentsInitializer.java
com.plattysoft.leonids.initializers.SpeeddModuleAndRangeInitializer.java
com.plattysoft.leonids.modifiers.AccelerationModifier.java
com.plattysoft.leonids.modifiers.AlphaModifier.java
com.plattysoft.leonids.modifiers.ParticleModifier.java
com.plattysoft.leonids.modifiers.ScaleModifier.java