ParticleTextView

来源:互联网 发布:php简单文字特效代码 编辑:程序博客网 时间:2024/06/02 07:29

ParticleTextView

https://github.com/Yasic/ParticleTextView


核心思想,还是比较巧妙的。怎么识别一副图片中字的每个像素的位置呢?把字体设置成3399ff,遍历所有的像素点,如果颜色3399ff, 然后把这个点位置记录下来。

很浪费时间吧。


    private void setParticles(){
        int centerX = getWidth() / 2;
        int centerY = getHeight() / 2;
        int[][] colorArray = bitmapTransition(centerX, centerY);
        int red, green, blue;
        particles = new Particle[(colorArray.length / rowStep) * colorArray[0].length / columnStep];
        int index = 0;
        for (int i = 0; i < colorArray.length; i += rowStep) {
            for (int j = 0; j < colorArray[0].length; j += columnStep) {
                red = Color.red(colorArray[i][j]);
                green = Color.green(colorArray[i][j]);
                blue = Color.blue(colorArray[i][j]);
                //This RGB group is the value of "#3399ff" which defined in initTextPaint() //
                if (red == 51 && green == 153 && blue == 255) {//判断是不是3399ff
                    particles[index] = new Particle(particleRadius, getRandomColor());
                    movingStrategy.setMovingPath(particles[index], getWidth(), getHeight(), new double[]{j, i});//保存位置。
                    particles[index].setVx((particles[index].getTargetX() - particles[index].getSourceX()) * releasing); //计算x方向速度
                    particles[index].setVy((particles[index].getTargetY() - particles[index].getSourceY()) * releasing);
                    index++;
                }
            }
        }
    }


步长值的设置,想清楚啊。如果步长太长,会丢失比划。如果太小,分散的点就会太密,不好看,但是轮廓很清晰。