Planet Animation
1. Put this code in (on create)
PlanetView bcv = new PlanetView(this);
linear1.addView(bcv);
2. Make Moreblock and name it (extra)
put this code
}
public class PlanetView extends View {
private double angle=0;
private Paint myPaint;
public PlanetView(Context context){
super(context);
myPaint = new Paint();
angle = 0;
}
@Override protected void onDraw(Canvas canvas) {
int viewWidth = this.getMeasuredWidth();
int viewHeight = this.getMeasuredHeight(); angle = (angle + 0.001)%360;
float x = Math.round(260*Math.sin(Math.toDegrees(angle)));
float y = Math.round(110*Math.cos(Math.toDegrees(angle)));
float x2 = Math.round(120*Math.sin(90+Math.toDegrees(angle)));
float y2 = Math.round(290*Math.cos(90+Math.toDegrees(angle)));
float x3 = Math.round(130*Math.sin(180+Math.toDegrees(angle)));
float y3 = Math.round(230*Math.cos(180+Math.toDegrees(angle)));
float x4 = Math.round(120*Math.sin(270+Math.toDegrees(angle)));
float y4 = Math.round(250*Math.cos(270+Math.toDegrees(angle)));
myPaint.setStyle(android.graphics.Paint.Style.FILL);
myPaint.setColor(Color.parseColor("#eceff1"));
canvas.drawCircle(viewWidth/2, viewHeight/2, (int)(x*1.5), myPaint);
myPaint.setColor(Color.parseColor("#cfd8dc"));
canvas.drawCircle(viewWidth/2, viewHeight/2, (int)(x*1.5)-25, myPaint);
myPaint.setColor(Color.parseColor("#275080")); canvas.drawCircle(viewWidth/2 + x, viewHeight/2 + y, 15, myPaint);
myPaint.setColor(Color.parseColor("#275080")); canvas.drawCircle(viewWidth/2 + x2, viewHeight/2 + y2, 20, myPaint);
myPaint.setColor(Color.parseColor("#275080")); canvas.drawCircle(viewWidth/2 + x3, viewHeight/2 + y3, 30, myPaint);
myPaint.setColor(Color.parseColor("#275080")); canvas.drawCircle(viewWidth/2 + x4, viewHeight/2 + y4, 10, myPaint);
android.graphics.drawable.Drawable d = getResources().getDrawable(R.drawable.earth, null);
d.setBounds((int)((viewWidth/2)-80-x/11), (int)((viewHeight/2)-80-x/11), (int)((viewWidth/2)+80+x/11), (int)((viewHeight/2)+80+x/11));
d.draw(canvas);
invalidate();
}
Comments
Post a Comment