java zip/gzip file compress and decompress Ricky

2023-01-23   ES  

Use a simple Animation action to simulate the moment of blasting, carefully adjust the effect of various parameters will be more like

Principles: Use the defined paper to spread from the central point of Ontouch to all directions. In the process of dispersing, use the unused speed, size, direction, rotation angle, transparency (here the paper can be added with flames, the effect will be better, the paper will be better, the paper will be better, the paper will be better. Burning represents transparency), position, 3D rotation;

//3D flip, the simulation force direction dive
Rotate3d rota3d = new Rotate3d((int) (Math.random()*90), (float) (Math.random()*90), 
(float) (Math.random()*x), (int) (Math.random()*y), 310.0f, true);  

//3D flip//Rotate3d rota3d = new Rotate3d((int) (Math.random()*90),
 //(float) (Math.random()*90,0, 0, 310.0f, true);  

3D action, Float Centerx, Float Center’s position can simulate the direction of the power. If it is all 0, it is scattered from the center

Although it seems a bit nonsense here, the effect is quite similar

  1 public class MainActivity extends Activity {
  2     private FrameLayout fl;
  3     //Define Bitmap object
  4     Bitmap    mBit = null;
  5     //AnimationSet animationSet;
  6     List<ExplosionView> exvArrayList = new ArrayList<ExplosionView>();
  7     List<AnimationSet> animationArrayList = new ArrayList<AnimationSet>();
  8     DisplayMetrics dm;
  9     private float dmw=0,dmh=0;
 10     //Define the shape of fragments
 11     private int s1 = R.drawable.s1,s2=R.drawable.s2,s3=R.drawable.s3,s4=R.drawable.s4,
 12             s5=R.drawable.s5,s6=R.drawable.s6,s7=R.drawable.s7,s8=R.drawable.s8,
 13             s9=R.drawable.s9,s10=R.drawable.s10,s11=R.drawable.s11,s12=R.drawable.s12,
 14             s13=R.drawable.s13,s14=R.drawable.s14;
 15     private int[] chip = {s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14};
 16     private int x=1;
 17     @Override
 18     public void onCreate(Bundle savedInstanceState) {
 19         super.onCreate(savedInstanceState);
 20         
 21         requestWindowFeature(Window.FEATURE_NO_TITLE);
 22         getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
 23                       WindowManager.LayoutParams. FLAG_FULLSCREEN);
 24         
 25         dm = new DisplayMetrics();   
 26         getWindowManager().getDefaultDisplay().getMetrics(dm);   
 27         //Get the width and height of the mobile phone as PX
 28         dmw = dm.widthPixels;
 29         dmh = dm.heightPixels;   
 30         
 31         fl = new FrameLayout(this);
 32         
 33         //Add 50 explosion fragments
 34         for (int i = 0; i < 50; i++) {
 35             int width=getResources().getDrawable(chip[x]).getIntrinsicWidth();
 36             int height=getResources().getDrawable(chip[x]).getIntrinsicHeight();
 37             fl.addView(createExv(chip[x],width,height));
 38             if(x==13){
 39                 x=0;
 40             }
 41             x++;
 42         }
 43         fl.setOnTouchListener(new LayoutListener());
 44         setContentView(fl);
 45     }
 46     
 47     public ExplosionView createExv(int chipx,int w,int h){
 48         ExplosionView exv = new ExplosionView(this,w,h);
 49         exv.setImageResource(chipx);
 50         exv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
 51         exv.setVisibility(View.INVISIBLE);    
 52         exvArrayList.add(exv);
 53         //animationArrayList.add(animationSet);
 54         return exv;
 55     }
 56 
 57     class LayoutListener implements OnTouchListener{
 58         
 59         public boolean onTouch(View v, MotionEvent event) {
 60             float x = event.getX();
 61             float y = event.getY();
 62             
 63 //            Iterator it1 = exvArrayList.iterator();   
 64 //            while(it1.hasNext()){   
 65 ////System.out.println(it1.next()); 
 66 //                ExplosionView tempExplosion = (ExplosionView) it1.next();
 67 //                tempExplosion.setVisibility(View.VISIBLE);
 68 //                tempExplosion.setLocation((int)y-20, (int)x-20);
 69 //                tempExplosion.startAnimation(animation);
 70 //            }   
 71             for(int i = 0;i < exvArrayList.size(); i ++){   
 72                 //System.out.println(exvArrayList.get(i));   
 73                 ExplosionView tempExplosion = (ExplosionView) exvArrayList.get(i);
 74                 tempExplosion.setVisibility(View.VISIBLE);
 75                 tempExplosion.setLocation((int)y, (int)x);
 76                 AnimationSet animationSet = new AnimationSet(false);
 77                 
 78                 //Set the transparency of fragments
 79                 AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
 80                 //Transparent action: deceleration
 81                 alpha.setInterpolator(new DecelerateInterpolator());
 82                 
 83                 
 84                 //Set the rotation angle of the fragments
 85                 RotateAnimation rotate = new RotateAnimation(0, (int) (Math.random()*330+30),
 86                         Animation.RELATIVE_TO_SELF, 0.5f,
 87                         Animation.RELATIVE_TO_SELF, 0.5f);
 88                 //Rotating action: deceleration
 89                 rotate.setInterpolator(new DecelerateInterpolator());
 90     
 91                 
 92                 //Set the movement of the fragments
 93                 TranslateAnimation translate = new TranslateAnimation(
 94                         0,
 95                         (float) ( dmw/2-(Math.random()*(dmw))),
 96                         0, 
 97                         (float) ( dmw/2-(Math.random()*(dmw))));
 98                 //Mobile action: deceleration
 99                 translate.setInterpolator(new DecelerateInterpolator());
100             
101                 //Set the size of the fragments
102                 ScaleAnimation scaleAnimation = new ScaleAnimation(
103                         1, (float)(Math.random()), 
104                         1, (float)(Math.random()),
105                         Animation.RELATIVE_TO_SELF, 0,
106                         Animation.RELATIVE_TO_SELF, 0);
107                 //Size Action: Acceleration
108                 scaleAnimation.setInterpolator(new AccelerateInterpolator());
109                 
110                 //3D flip, the simulation force direction dive
111                 Rotate3d rota3d = new Rotate3d((int) (Math.random()*90), (float) (Math.random()*90), 
112                         (float) (Math.random()*x), (int) (Math.random()*y), 310.0f, true);  
113                 //Rotate3d rota3d = new Rotate3d((int) (Math.random()*90), (float) (Math.random()*90), 
114 //        0, 0, 310.0f, true);  
115                 
116                 
117                 animationSet.addAnimation(alpha);
118                 animationSet.addAnimation(rotate);
119                 animationSet.addAnimation(translate);
120                 animationSet.addAnimation(rota3d);
121                 animationSet.addAnimation(scaleAnimation);
122                 
123                 //Animation duration, so that the movement speed of each fragment is different124 //animationSet.setDuration(5000);
125                 animationSet.setDuration((int) (Math.random()*4000+100));
126                 //Start pause time
127                 animationSet.setStartOffset(0);
128                 animationSet.setFillAfter(true);
129                 
130                 tempExplosion.startAnimation(animationSet);
131             }   
132 
133             return false;
134         }
135     }
136     
137     class ExplosionView extends ImageView{
138         private int exvw,exvh;
139         public ExplosionView(Context context,int ew,int eh) {
140             super(context);
141             this.exvw=ew;
142             this.exvh=eh;
143         }
144         //handle the location of the explosion
145         public void setLocation(int top,int left){
146             this.setFrame(left, top, left+exvw, top+exvh);
147         }    
148     }
149     
150     class Rotate3d extends Animation{   
151         private final float mFromDegrees;      
152         private final float mToDegrees;      
153         private final float mCenterX;      
154         private final float mCenterY;      
155         private final float mDepthZ;      
156         private final boolean mReverse;      
157         private Camera mCamera;  
158         
159         public Rotate3d(float fromDegrees, float toDegrees,float centerX, float centerY, 
160                 float depthZ, boolean reverse) {          
161             mFromDegrees = fromDegrees;          
162             mToDegrees = toDegrees;          
163             mCenterX = centerX;          
164             mCenterY = centerY;          
165             mDepthZ = depthZ;          
166             mReverse = reverse;      
167         }    
168         
169         @Override      
170         public void initialize(int width, int height, int parentWidth, int parentHeight) {          
171             super.initialize(width, height, parentWidth, parentHeight);          
172             mCamera = new Camera();      
173         }     
174         
175         @Override      
176         protected void applyTransformation(float interpolatedTime, Transformation t) {          
177             final float fromDegrees = mFromDegrees;          
178             float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);          
179             final float centerX = mCenterX;          
180             final float centerY = mCenterY;          
181             final Camera camera = mCamera;          
182             final Matrix matrix = t.getMatrix();          
183             camera.save();          
184             if (mReverse) {              
185                 camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);          
186             } else {              
187                 camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));          
188             }          
189             
190             camera.rotateY(degrees);          
191             camera.getMatrix(matrix);          
192             camera.restore();           
193             matrix.preTranslate(-centerX, -centerY);          
194             matrix.postTranslate(centerX, centerY);      
195             }  
196         } 

source

Related Posts

DRAWINSTANCE and the difference in performance differences in the case of no combination

15 useful JavaScript and CSS libraries

Synchronized differences on ordinary synchronization methods and static methods

2021 Niuke Summer Multi-School Training Camp 4-H Question NEP

java zip/gzip file compress and decompress Ricky

Random Posts

Non -initial warning warning

Authorization and microservices mutual certification

Android Studio Common plug -in and dependent ABNER

Record a lot of errors in YOLOV5

BZOJ4552 && Luo Valley P2824 [Heoi2016/TJOI2016] Sort