ManyCircle
来源:互联网 发布:网络的宣传语 编辑:程序博客网 时间:2024/06/05 22:42
public class ManyCircle extends View{ private Paint paint; private int maxRadius = 16; private ValueAnimator valueAnimator; private boolean init = false; private float radiu = 10; public ManyCircle(Context context, AttributeSet attrs) { super(context, attrs); init(); } public ManyCircle(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setColor(Color.RED); } private int width; private int height; private float pi2; private float r; @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!init) { init = true; start(); width = getWidth() / 2; height = getHeight() / 2; pi2 = 2*(float)Math.PI; r = width-maxRadius; } canvas.drawCircle((float) (width + r * Math.sin(0)), (float) (height + r * Math.cos(0)), f(radiu+0), paint); canvas.drawCircle((float) (width + r * Math.sin(pi2 /8)), (float) (height + r * Math.cos(pi2 /8)), f(radiu+2), paint); canvas.drawCircle((float) (width + r * Math.sin(pi2 /8*2)), (float) (height + r * Math.cos(pi2 /8*2)), f(radiu+4), paint); canvas.drawCircle((float) (width + r * Math.sin(pi2 /8*3)), (float) (height + r * Math.cos(pi2 /8*3)), f(radiu+6), paint); canvas.drawCircle((float) (width + r * Math.sin(pi2 /8*4)), (float) (height + r * Math.cos(pi2 /8*4)), f(radiu+8), paint); canvas.drawCircle((float) (width + r * Math.sin(pi2 /8*5)), (float) (height + r * Math.cos(pi2 /8*5)), f(radiu+10), paint); canvas.drawCircle((float) (width + r * Math.sin(pi2 /8*6)), (float) (height + r * Math.cos(pi2 /8*6)), f(radiu+12), paint); canvas.drawCircle((float) (width + r * Math.sin(pi2 /8*7)), (float) (height + r * Math.cos(pi2 /8*7)), f(radiu+14), paint); if (valueAnimator.isRunning()) { radiu = (float) valueAnimator.getAnimatedValue(); invalidate(); } } private void start() { if (valueAnimator == null) { valueAnimator = ValueAnimator.ofFloat(0, maxRadius); valueAnimator.setInterpolator(new LinearInterpolator()); valueAnimator.setDuration(1000); valueAnimator.start(); }else { valueAnimator.start(); } postDelayed(new Runnable() { @Override public void run() { start(); invalidate(); } }, valueAnimator.getDuration()); invalidate(); } //分段函数 private float f(float x) { if (x <=maxRadius / 2) { return x; } else if(x<maxRadius){ return maxRadius - x; }else if(x<maxRadius*3/2) { return x-maxRadius; }else { return 2*maxRadius-x; } }}
阅读全文
0 0
- ManyCircle
- 新增公众号门店,php开发微信门店管理
- java线程池的初步理解
- “3D码农 ”紧缺!“新经济”急需大量“数字工匠”
- 奇数还是偶数?
- mybatis的example
- ManyCircle
- 整合多个txt文件到csv文件中(使用c++)
- LeetCode-581. Shortest Unsorted Continuous Subarray
- ajax
- banner的使用--pizifusheng
- EasyUI 分页
- web框架express安装初体验
- Python内建函数之——filter,map,reduce
- C++设计模式10--命令模式(二)(Command)--降低请求发送者与接收者耦合