代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
水波扩散效果
作者:
Tobe1
/ 发布于
2014/12/13
/
634
package com.phodev.andtools.widget; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; import android.util.AttributeSet; import android.view.View; import android.view.animation.CycleInterpolator; import android.view.animation.Interpolator; /** * 水波效果 * * @author sky * */ public class WaterWaveView extends View { private final static int FPS = 1000 / 40; private float mMaxWaveAreaRadius; private float mWaveIntervalSize; private float mStirStep;// 波移动的步幅 private float mWaveStartWidth;// px private float mWaveEndWidth;// px private int mWaveColor; /** 颜色渐变控制器 */ private Interpolator interpolator = new CycleInterpolator(0.5f); private float mViewCenterX; private float mViewCenterY; private final Paint mWavePaint = new Paint(); { mWavePaint.setAntiAlias(true); mWavePaint.setStyle(Style.STROKE); } private final Paint mWaveCenterShapePaint = new Paint(); { mWaveCenterShapePaint.setAntiAlias(true); mWaveCenterShapePaint.setStyle(Style.FILL); } private boolean mFillAllView = false; private float mFillWaveSourceShapeRadius; private final List<Wave> mWaves = new ArrayList<Wave>(); public WaterWaveView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public WaterWaveView(Context context) { super(context); init(); } private void init() { setWaveInfo(60f, 2f, 2f, 15f, Color.BLUE); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); mViewCenterX = getWidth() / 2; mViewCenterY = getHeight() / 2; float waveAreaRadius = mMaxWaveAreaRadius; if (mFillAllView) { waveAreaRadius = (float) Math.sqrt(mViewCenterX * mViewCenterX + mViewCenterY * mViewCenterY); } else { waveAreaRadius = Math.min(mViewCenterX, mViewCenterY); } if (mMaxWaveAreaRadius != waveAreaRadius) { mMaxWaveAreaRadius = waveAreaRadius; resetWave(); } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); stir(); for (Wave w : mWaves) { mWavePaint.setColor(w.color); mWavePaint.setStrokeWidth(w.width); canvas.drawCircle(mViewCenterX, mViewCenterY, w.radius, mWavePaint); } if (mFillWaveSourceShapeRadius > 0f) { canvas.drawCircle(mViewCenterX, mViewCenterY, mFillWaveSourceShapeRadius, mWaveCenterShapePaint); } postInvalidateDelayed(FPS); } /** * 波 * * @author sky */ class Wave { public float radius; public float width; public int color; public Wave() { reset(); } public void reset() { radius = 0; width = mWaveStartWidth; color = mWaveColor; } @Override public String toString() { return "Wave [radius=" + radius + ", width=" + width + ", color=" + color + "]"; } } private Wave mLastRmoveWave; /** * 触发涌动传播 */ private void stir() { Wave nearestWave = mWaves.isEmpty() ? null : mWaves.get(0); if (nearestWave == null || nearestWave.radius >= mWaveIntervalSize) { Wave w = null; if (mLastRmoveWave != null) { w = mLastRmoveWave; mLastRmoveWave = null; w.reset(); } else { w = new Wave(); } mWaves.add(0, w); } float waveWidthIncrease = mWaveEndWidth - mWaveStartWidth; int size = mWaves.size(); for (int i = 0; i < size; i++) { Wave w = mWaves.get(i); float rP = w.radius / mMaxWaveAreaRadius; if (rP > 1f) { rP = 1f; } w.width = mWaveStartWidth + rP * waveWidthIncrease; w.radius += mStirStep; float factor = interpolator.getInterpolation(rP); w.color = mWaveColor & 0x00FFFFFF | ((int) (255 * factor) << 24); } Wave farthestWave = mWaves.get(size - 1); if (farthestWave.radius > mMaxWaveAreaRadius + farthestWave.width / 2) { mWaves.remove(size - 1); } } /** * 如果true会选择view的最大的对角线作为活动半径 * * @param fillAllView */ public void setFillAllView(boolean fillAllView) { mFillAllView = fillAllView; resetWave(); } public void resetWave() { mWaves.clear(); postInvalidate(); } /** * 填充波形起源的中心点 * * @param radius * 半径大小 */ public void setFillWaveSourceShapeRadius(float radius) { mFillWaveSourceShapeRadius = radius; } /** * 设置波形属性 * * @param intervalSize * 两个波形之间的间距 * @param stireStep * 波形移动速度 * @param startWidth * 起始波形宽度 * @param endWidth * 终止波形宽度 * @param color * 波形颜色 */ public void setWaveInfo(float intervalSize, float stireStep, float startWidth, float endWidth, int color) { mWaveIntervalSize = intervalSize; mStirStep = stireStep; mWaveStartWidth = startWidth; mWaveEndWidth = endWidth; setWaveColor(color); resetWave(); } /** * 设置波形颜色 * * @param color */ public void setWaveColor(int color) { mWaveColor = color; mWaveCenterShapePaint.setColor(mWaveColor); } }
试试其它关键字
水波扩散
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Tobe1
贡献的其它代码
(
7
)
.
php缩略图函数
.
水波扩散效果
.
数组对象增加一个返回随机元素的方法
.
iOS 放射状圆环
.
蛇形填数
.
生命繁衍游戏
.
最长回文字串的实现
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3