建立在Android的触摸战平喷涂效果 [英] Creating a spray effect on touch draw in android

查看:92
本文介绍了建立在Android的触摸战平喷涂效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要我创造喷雾般的效果,当用户触摸屏幕。用户具有选择颜色的选项。我需要创建类似的颜色用户选择的效果喷雾。我不知道如果它的可能与否。如果有可能请建议我一个链接或引导办理。

My application requires me to create spray like effect when user touches the screen. The user has the option of choosing a color. I need to create a spray like effect with the color user chooses. I am not sure if its possible or not. If it possible please suggest me a link or a guide to go through.

推荐答案

您刚刚使用公用平局部分在画布上......然后指定一个半径被吸引到。然后使用随机功能,绘制(x)的数量的点所定义使用半径为只要用户是pressing向下的圆的区域内。如果您需要更详细的帮助,请让我知道。

You'd just use the common draw part on the canvas... then specify a radius to be drawn to. Then using the 'random' function, draw (x) number of dots inside the area of the circle you defined using the radius for as long as the user is pressing down. If you need more exact help please let me know.

这将是非常伪code。但是,你应该很容易能够从这个让你的code的工作。

This is going to be very pseudo-code. But you should very easily be able to make your code work from this.

// This needs to happen in the down press on the canvas
if(currentBrush == Brush.SPRAY_CAN){
    int dotsToDrawAtATime = 20;
    double brushRadius = 1.0; // This is however large they set the brush size, could be (1), could be whatever the max size of your brush is, e.g., (50), but set it based on what they choose

    for (int i = 0; i < dotsToDrawAtATime; i++){
        // Pick a random color for single dot to draw
        // Get the circumference of the circle (2*pi*brushRadius), based on the X/Y that the user input when they pressed down. Pick a random spot inside that area, and draw a single dot. As this is a for loop, it will happen 20 different times for this one occurrence.
    }
}

如果你要使用这个,我会的的考虑将这样做的Iain_b的方式。请把他的职位考虑。

If you're going to use this, I would highly consider incorporating Iain_b's way of doing this. Please take his post into consideration.

这里有一个图片...也许这将帮助你了解...

Here's an image... maybe this will help you to understand...

下面是我的code更新lain_b的增加部分,以帮助简化它。

Here's my code updated with lain_b's added part to help simplify it.

// This needs to happen in the down press on the canvas
if(currentBrush == Brush.SPRAY_CAN){
    int dotsToDrawAtATime = 20;
    double brushRadius = 1.0; // This is however large they set the brush size, could be (1), could be whatever the max size of your brush is, e.g., (50), but set it based on what they choose

    for (int i = 0; i < dotsToDrawAtATime; i++){
        // Pick a random color for single dot to draw
        ...

        // Get the location to draw to
        int x = touchedX + Random.nextGaussian()*brushRadius;
        int y = touchedY + Random.nextGaussian()*brushRadius;

        // Draw the point, using the random color, and the X/Y value
        ...
    }
}

这篇关于建立在Android的触摸战平喷涂效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆