您的位置:首页 > 移动开发 > Android开发

浪漫桃心的Android表白程序

2016-08-18 11:29 344 查看
本文转载于 huachao1001的专栏

几年前,看到过有个牛人用HTML5绘制了浪漫的爱心表白动画。地址在这:浪漫程序员 HTML5爱心表白动画。发现原来程序员也是可以很浪……漫…..的。那么在Android怎么打造如此这个效果呢?参考了一下前面HTML5的算法,在Android中实现了类似的效果。先贴上最终效果图:

package com.hc.testheart;

import android.graphics.Color;

/**
* Package com.example.administrator.testrecyclerview
* Created by HuaChao on 2016/5/25.
*/
public class MyUtil {

public static float circle = (float) (2 * Math.PI);

public static int rgba(int r, int g, int b, int a) {
return Color.argb(a, r, g, b);
}

public static int randomInt(int min, int max) {
return (int) Math.floor(Math.random() * (max - min + 1)) + min;
}

public static float random(float min, float max) {
return (float) (Math.random() * (max - min) + min);
}

//产生随机的argb颜色
public static int randomrgba(int rmin, int rmax, int gmin, int gmax, int bmin, int bmax, int a) {
int r = Math.round(random(rmin, rmax));
int g = Math.round(random(gmin, gmax));
int b = Math.round(random(bmin, bmax));
int limit = 5;
if (Math.abs(r - g) <= limit && Math.abs(g - b) <= limit && Math.abs(b - r) <= limit) {
return rgba(rmin, rmax, gmin, gmax);
} else {
return rgba(r, g, b, a);
}
}

//角度转弧度
public static float degrad(float angle) {
return circle / 360 * angle;
}
}


View Code

好了,目前为止,就可以得到上面的效果了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: