There is a FingerPaint demo in APIDemos of Android. Below is the code when finger moving on the screen.
Android的APIDemos中有一个FingerPaint演示。下面是手指在屏幕上移动时的代码。
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;
}
}
I notice this the demo use mPath.quadTo which I thought should be mPath.lineTo, and I tried. Below is my code:
我注意到这个演示使用mPath.quadTo我认为应该是mPath.lineTo,我试过了。以下是我的代码:
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.lineTo(x, y);
mX = x;
mY = y;
}
}
Then I tried again, seems no difference, why Google use quadTo?
然后我再试一次,似乎没什么区别,为什么谷歌使用quadTo?
I heard in Game Program, they use quadTo to draw finger paint, but why? Plz help...thx
我在游戏程序中听说过,他们使用quadTo绘制手指画,但为什么呢? Plz帮助... thx
2 个解决方案
#1
4
QUad to curves using a quadratic line (basically an ellipse of some sort). LineTo is a straight line. QuadTo will smooth out jaggedies where they turn.
使用二次线(基本上是某种椭圆)对曲线进行四次曲线。 LineTo是一条直线。 QuadTo可以消除它们转向的锯齿状。
#2
4
According to http://developer.android.com/reference/android/graphics/Path.html:
根据http://developer.android.com/reference/android/graphics/Path.html:
quadTo(float x1, float y1, float x2, float y2) Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2).. lineTo(float x, float y)Add a line from the last point to the specified point (x,y).
quadTo(float x1,float y1,float x2,float y2)从最后一个点添加二次贝塞尔曲线,接近控制点(x1,y1),结束于(x2,y2).. lineTo(float x,float y)从最后一个点到指定点(x,y)添加一条线。
Looks like quadTo() draws a curved line, based on some Quadratic function, or in other words, a parabola. lineTo() just draws a straight line.
看起来像quadTo()绘制一条曲线,基于一些二次函数,或者换句话说,抛物线。 lineTo()只画一条直线。
#1
4
QUad to curves using a quadratic line (basically an ellipse of some sort). LineTo is a straight line. QuadTo will smooth out jaggedies where they turn.
使用二次线(基本上是某种椭圆)对曲线进行四次曲线。 LineTo是一条直线。 QuadTo可以消除它们转向的锯齿状。
#2
4
According to http://developer.android.com/reference/android/graphics/Path.html:
根据http://developer.android.com/reference/android/graphics/Path.html:
quadTo(float x1, float y1, float x2, float y2) Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2).. lineTo(float x, float y)Add a line from the last point to the specified point (x,y).
quadTo(float x1,float y1,float x2,float y2)从最后一个点添加二次贝塞尔曲线,接近控制点(x1,y1),结束于(x2,y2).. lineTo(float x,float y)从最后一个点到指定点(x,y)添加一条线。
Looks like quadTo() draws a curved line, based on some Quadratic function, or in other words, a parabola. lineTo() just draws a straight line.
看起来像quadTo()绘制一条曲线,基于一些二次函数,或者换句话说,抛物线。 lineTo()只画一条直线。