本文整理汇总了Java中android.graphics.Path.cubicTo方法的典型用法代码示例。如果您正苦于以下问题:Java Path.cubicTo方法的具体用法?Java Path.cubicTo怎么用?Java Path.cubicTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Path
的用法示例。
在下文中一共展示了Path.cubicTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawWind
import android.graphics.Path; //导入方法依赖的package包/类
private void drawWind(Canvas canvas) {
mWindPath = new Path();
canvas.drawCircle(mCenterPoint.x,mCenterPoint.y,width/40,mWindmillPaint);
mWindPath.moveTo(x1,y1);
x2 = mCenterPoint.x + (float) (r1 * Math.cos(rad1 + angle));
y2 = mCenterPoint.y + (float) (r1 * Math.sin(rad1 + angle));
x3 = mCenterPoint.x + (float) (r2 * Math.cos(rad2 + angle));
y3 = mCenterPoint.y + (float) (r2 * Math.sin(rad2 + angle));
x4 = mCenterPoint.x + (float) (r3 * Math.cos(rad3 + angle));
y4 = mCenterPoint.y + (float) (r3 * Math.sin(rad3 + angle));
x5 = mCenterPoint.x + (float) (r4 * Math.cos(rad4 + angle));
y5 = mCenterPoint.y + (float) (r4 * Math.sin(rad4 + angle));
mWindPath.cubicTo(x2,y2,x3,y3,x4,y4);
mWindPath.quadTo(x5,y5,x1,y1);
mWindPath.close();
canvas.drawPath(mWindPath,mWindmillPaint);
canvas.rotate(120,mCenterPoint.x,mCenterPoint.y);
canvas.drawPath(mWindPath,mWindmillPaint);
canvas.rotate(120,mCenterPoint.x,mCenterPoint.y);
canvas.drawPath(mWindPath,mWindmillPaint);
canvas.rotate(120,mCenterPoint.x,mCenterPoint.y);
}
示例2: createChildPath
import android.graphics.Path; //导入方法依赖的package包/类
private Path createChildPath() {
float bezierOffset = mChildOvalRadius * OVAL_BEZIER_FACTOR;
Path path = new Path();
path.moveTo(mChildPosition[0], mChildPosition[1] - mChildOvalRadius);
//left_top arc
path.cubicTo(mChildPosition[0] - bezierOffset - mChildLeftXOffset, mChildPosition[1] - mChildOvalRadius,
mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1] - bezierOffset + mChildLeftYOffset,
mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1]);
//left_bottom arc
path.cubicTo(mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1] + bezierOffset - mChildLeftYOffset,
mChildPosition[0] - bezierOffset - mChildLeftXOffset, mChildPosition[1] + mChildOvalRadius,
mChildPosition[0], mChildPosition[1] + mChildOvalRadius);
//right_bottom arc
path.cubicTo(mChildPosition[0] + bezierOffset + mChildRightXOffset, mChildPosition[1] + mChildOvalRadius,
mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1] + bezierOffset - mChildRightYOffset,
mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1]);
//right_top arc
path.cubicTo(mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1] - bezierOffset + mChildRightYOffset,
mChildPosition[0] + bezierOffset + mChildRightXOffset, mChildPosition[1] - mChildOvalRadius,
mChildPosition[0], mChildPosition[1] - mChildOvalRadius);
return path;
}
示例3: createArcPath
import android.graphics.Path; //导入方法依赖的package包/类
protected Path createArcPath(View view, float endX, float endY, float radius){
Path arcPath=new Path();
float startX=view.getTranslationX();
float startY=view.getTranslationY();
float midX = startX + ((endX - startX) / 2);
float midY = startY + ((endY - startY) / 2);
float xDiff = midX - startX;
float yDiff = midY - startY;
double angle = (Math.atan2(yDiff, xDiff) * (180 / Math.PI)) - 90;
double angleRadians = Math.toRadians(angle);
float pointX = (float) (midX + radius * Math.cos(angleRadians));
float pointY = (float) (midY + radius * Math.sin(angleRadians));
arcPath.moveTo(startX, startY);
arcPath.cubicTo(startX,startY,pointX,pointY, endX, endY);
return arcPath;
}
示例4: makePathAndBoundingBox
import android.graphics.Path; //导入方法依赖的package包/类
private Path makePathAndBoundingBox(SVG.Circle obj) {
float cx = (obj.cx != null) ? obj.cx.floatValueX(this) : 0f;
float cy = (obj.cy != null) ? obj.cy.floatValueY(this) : 0f;
float r = obj.r.floatValue(this);
float left = cx - r;
float top = cy - r;
float right = cx + r;
float bottom = cy + r;
if (obj.boundingBox == null) {
obj.boundingBox = new Box(left, top, r * 2, r * 2);
}
float cp = r * BEZIER_ARC_FACTOR;
Path p = new Path();
p.moveTo(cx, top);
p.cubicTo(cx + cp, top, right, cy - cp, right, cy);
p.cubicTo(right, cy + cp, cx + cp, bottom, cx, bottom);
p.cubicTo(cx - cp, bottom, left, cy + cp, left, cy);
p.cubicTo(left, cy - cp, cx - cp, top, cx, top);
p.close();
return p;
}
示例5: createWaitPath
import android.graphics.Path; //导入方法依赖的package包/类
private Path createWaitPath(RectF bounds) {
Path path = new Path();
//create circle
path.moveTo(bounds.centerX() + mWaitCircleRadius, bounds.centerY());
//create w
path.cubicTo(bounds.centerX() + mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius * 0.5f,
bounds.centerX() + mWaitCircleRadius * 0.3f, bounds.centerY() - mWaitCircleRadius,
bounds.centerX() - mWaitCircleRadius * 0.35f, bounds.centerY() + mWaitCircleRadius * 0.5f);
path.quadTo(bounds.centerX() + mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius,
bounds.centerX() + mWaitCircleRadius * 0.05f, bounds.centerY() + mWaitCircleRadius * 0.5f);
path.lineTo(bounds.centerX() + mWaitCircleRadius * 0.75f, bounds.centerY() - mWaitCircleRadius * 0.2f);
path.cubicTo(bounds.centerX(), bounds.centerY() + mWaitCircleRadius * 1f,
bounds.centerX() + mWaitCircleRadius, bounds.centerY() + mWaitCircleRadius * 0.4f,
bounds.centerX() + mWaitCircleRadius, bounds.centerY());
//create arc
path.arcTo(new RectF(bounds.centerX() - mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius,
bounds.centerX() + mWaitCircleRadius, bounds.centerY() + mWaitCircleRadius), 0, -359);
path.arcTo(new RectF(bounds.centerX() - mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius,
bounds.centerX() + mWaitCircleRadius, bounds.centerY() + mWaitCircleRadius), 1, -359);
path.arcTo(new RectF(bounds.centerX() - mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius,
bounds.centerX() + mWaitCircleRadius, bounds.centerY() + mWaitCircleRadius), 2, -2);
//create w
path.cubicTo(bounds.centerX() + mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius * 0.5f,
bounds.centerX() + mWaitCircleRadius * 0.3f, bounds.centerY() - mWaitCircleRadius,
bounds.centerX() - mWaitCircleRadius * 0.35f, bounds.centerY() + mWaitCircleRadius * 0.5f);
path.quadTo(bounds.centerX() + mWaitCircleRadius, bounds.centerY() - mWaitCircleRadius,
bounds.centerX() + mWaitCircleRadius * 0.05f, bounds.centerY() + mWaitCircleRadius * 0.5f);
path.lineTo(bounds.centerX() + mWaitCircleRadius * 0.75f, bounds.centerY() - mWaitCircleRadius * 0.2f);
path.cubicTo(bounds.centerX(), bounds.centerY() + mWaitCircleRadius * 1f,
bounds.centerX() + mWaitCircleRadius, bounds.centerY() + mWaitCircleRadius * 0.4f,
bounds.centerX() + mWaitCircleRadius, bounds.centerY());
return path;
}
示例6: createPath
import android.graphics.Path; //导入方法依赖的package包/类
static Path createPath(PointF startPoint, PointF endPoint, PointF cp1, PointF cp2) {
Path path = new Path();
path.moveTo(startPoint.x, startPoint.y);
if (cp1 != null && cp1.length() != 0 && cp2 != null && cp2.length() != 0) {
path.cubicTo(
startPoint.x + cp1.x, startPoint.y + cp1.y,
endPoint.x + cp2.x, endPoint.y + cp2.y,
endPoint.x, endPoint.y);
} else {
path.lineTo(endPoint.x, endPoint.y);
}
return path;
}
示例7: getPath
import android.graphics.Path; //导入方法依赖的package包/类
Path getPath() {
Path path = new Path();
path.moveTo(LEFT_CURVE[0].x, LEFT_CURVE[0].y);
path.quadTo(LEFT_CURVE[1].x, LEFT_CURVE[1].y, LEFT_CURVE[2].x, LEFT_CURVE[2].y);
path.cubicTo(CURVE_CTR[3].x, CURVE_CTR[3].y, CURVE_CTR[2].x, CURVE_CTR[2].y, RIGHT_CURVE[2].x, RIGHT_CURVE[2].y);
path.quadTo(RIGHT_CURVE[1].x, RIGHT_CURVE[1].y, RIGHT_CURVE[0].x, RIGHT_CURVE[0].y);
path.cubicTo(CURVE_CTR[0].x, CURVE_CTR[0].y, CURVE_CTR[1].x, CURVE_CTR[1].y, LEFT_CURVE[0].x, LEFT_CURVE[0].y);
return path;
}
示例8: createCubic
import android.graphics.Path; //导入方法依赖的package包/类
private static Path createCubic(float controlX1, float controlY1,
float controlX2, float controlY2) {
final Path path = new Path();
path.moveTo(0.0f, 0.0f);
path.cubicTo(controlX1, controlY1, controlX2, controlY2, 1.0f, 1.0f);
return path;
}
示例9: createWaterPath
import android.graphics.Path; //导入方法依赖的package包/类
private Path createWaterPath(RectF waterRect, float progress) {
Path path = new Path();
path.moveTo(waterRect.left, waterRect.top);
//Similar to the way draw the bottle's bottom sides
float radius = (waterRect.width() - mStrokeWidth) / 2.0f;
float centerY = waterRect.bottom - 0.86f * radius;
float bottleBottomWidth = waterRect.width() / 2.0f;
RectF bodyRect = new RectF(waterRect.left, centerY - radius, waterRect.right, centerY + radius);
path.addArc(bodyRect, 187.5f, -67.5f);
path.lineTo(waterRect.centerX() - bottleBottomWidth / 2.0f, waterRect.bottom);
path.lineTo(waterRect.centerX() + bottleBottomWidth / 2.0f, waterRect.bottom);
path.addArc(bodyRect, 60, -67.5f);
//draw the water waves
float cubicXChangeSize = waterRect.width() * 0.35f * progress;
float cubicYChangeSize = waterRect.height() * 1.2f * progress;
path.cubicTo(waterRect.left + waterRect.width() * 0.80f - cubicXChangeSize, waterRect.top - waterRect.height() * 1.2f + cubicYChangeSize,
waterRect.left + waterRect.width() * 0.55f - cubicXChangeSize, waterRect.top - cubicYChangeSize,
waterRect.left, waterRect.top - mStrokeWidth / 2.0f);
path.lineTo(waterRect.left, waterRect.top);
return path;
}
示例10: onDraw
import android.graphics.Path; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 绘制数据点和控制点
mPaint.setColor(Color.GRAY);
mPaint.setStrokeWidth(20);
mPaint.setAntiAlias(true);
canvas.drawPoint(start.x, start.y, mPaint);
canvas.drawPoint(end.x, end.y, mPaint);
canvas.drawPoint(control1.x, control1.y, mPaint);
// 绘制辅助线
mPaint.setStrokeWidth(4);
canvas.drawLine(start.x, start.y, control1.x, control1.y, mPaint);
canvas.drawLine(control1.x, control1.y, control2.x, control2.y, mPaint);
canvas.drawLine(control2.x, control2.y, end.x, end.y, mPaint);
// 绘制贝塞尔曲线
mPaint.setColor(Color.RED);
mPaint.setStrokeWidth(8);
mPaint.setStyle(Paint.Style.STROKE);
Path path = new Path();
path.moveTo(start.x, start.y);
/**
* (float x1, float y1, float x2, float y2,
float x3, float y3)
*/
path.cubicTo(control1.x, control1.y, control2.x, control2.y, end.x, end.y);
canvas.drawPath(path, mPaint);
}
示例11: getPathFromData
import android.graphics.Path; //导入方法依赖的package包/类
static void getPathFromData(ShapeData shapeData, Path outPath) {
outPath.reset();
PointF initialPoint = shapeData.getInitialPoint();
outPath.moveTo(initialPoint.x, initialPoint.y);
for (int i = 0; i < shapeData.getCurves().size(); i++) {
CubicCurveData curveData = shapeData.getCurves().get(i);
outPath.cubicTo(curveData.getControlPoint1().x, curveData.getControlPoint1().y,
curveData.getControlPoint2().x, curveData.getControlPoint2().y,
curveData.getVertex().x, curveData.getVertex().y);
}
if (shapeData.isClosed()) {
outPath.close();
}
}
示例12: createPath
import android.graphics.Path; //导入方法依赖的package包/类
/**
* 利用三次贝塞尔构造减速加速函数
* @param segmentLength 从起点到每一段终点的长度集合
* @return
*/
public Path createPath(float[] segmentLength){
Path path = new Path();
float ratio;
PointF start = new PointF();
PointF con1 = new PointF();
PointF con2 = new PointF();
PointF end = new PointF();
float totalLength = segmentLength[segmentLength.length - 1];
for (int i = 0; i < segmentLength.length; i++) {
ratio = segmentLength[i] / totalLength;
if(i == 0){
start.x = originStart.x;
start.y = originStart.y;
path.moveTo(originStart.x,originStart.y);
}
end.x = intervalX * ratio;
end.y = intervalY * ratio;
con1.x = start.x + (end.x - start.x) * bezierControlRatioX;
con1.y = start.y + (end.y - start.y) * bezierControlRatioY;
con2.x = end.x - (end.x - start.x) * (bezierControlRatioX );
con2.y = end.y - (end.y - start.y) * (bezierControlRatioY );
path.cubicTo(con1.x,con1.y,
con2.x,con2.y,
end.x,end.y);
// Log.d("ccy","startx,y = "+start.x+";"+start.y);
// Log.d("ccy","con1x,y = "+con1.x+";"+con1.y);
// Log.d("ccy","con2x,y = "+con2.x+";"+con2.y);
// Log.d("ccy","endx,y = "+end.x+";"+end.y);
start.x = end.x;
start.y = end.y;
}
return path;
}
示例13: createLinkPath
import android.graphics.Path; //导入方法依赖的package包/类
private Path createLinkPath() {
Path path = new Path();
float bezierOffset = mMotherOvalHalfWidth * OVAL_BEZIER_FACTOR;
float distance = (float) Math.sqrt(Math.pow(mMotherPosition[0] - mChildPosition[0], 2.0f) + Math.pow(mMotherPosition[1] - mChildPosition[1], 2.0f));
if (distance <= mMotherOvalHalfWidth + mChildOvalRadius * 1.2f
&& distance >= mMotherOvalHalfWidth - mChildOvalRadius * 1.2f) {
float maxOffsetY = 2 * mChildOvalRadius * 1.2f;
float offsetRate = (distance - (mMotherOvalHalfWidth - mChildOvalRadius * 1.2f)) / maxOffsetY;
float mMotherOvalOffsetY = mMotherOvalHalfHeight - offsetRate * (mMotherOvalHalfHeight - mChildOvalRadius) * 0.85f;
mMotherOvalPath.addOval(new RectF(mMotherPosition[0] - mMotherOvalHalfWidth, mMotherPosition[1] - mMotherOvalOffsetY,
mMotherPosition[0] + mMotherOvalHalfWidth, mMotherPosition[1] + mMotherOvalOffsetY), Path.Direction.CW);
float mMotherXOffset = distance - mMotherOvalHalfWidth + mChildOvalRadius;
float distanceUltraLeft = (float) Math.sqrt(Math.pow(mMotherPosition[0] - mMotherOvalHalfWidth - mChildPosition[0], 2.0f)
+ Math.pow(mMotherPosition[1] - mChildPosition[1], 2.0f));
float distanceUltraRight = (float) Math.sqrt(Math.pow(mMotherPosition[0] + mMotherOvalHalfWidth - mChildPosition[0], 2.0f)
+ Math.pow(mMotherPosition[1] - mChildPosition[1], 2.0f));
path.moveTo(mMotherPosition[0], mMotherPosition[1] + mMotherOvalOffsetY);
if (distanceUltraRight < distanceUltraLeft) {
//right_bottom arc
path.cubicTo(mMotherPosition[0] + bezierOffset + mMotherXOffset, mMotherPosition[1] + mMotherOvalOffsetY,
mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1] + mChildOvalRadius * 1.5f,
mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1]);
//right_top arc
path.cubicTo(mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1] - mChildOvalRadius * 1.5f,
mMotherPosition[0] + bezierOffset + mMotherXOffset, mMotherPosition[1] - mMotherOvalOffsetY,
mMotherPosition[0], mMotherPosition[1] - mMotherOvalOffsetY);
} else {
//left_bottom arc
path.cubicTo(mMotherPosition[0] - bezierOffset - mMotherXOffset, mMotherPosition[1] + mMotherOvalOffsetY,
mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1] + mChildOvalRadius * 1.5f,
mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1]);
//left_top arc
path.cubicTo(mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1] - mChildOvalRadius * 1.5f,
mMotherPosition[0] - bezierOffset - mMotherXOffset, mMotherPosition[1] - mMotherOvalOffsetY,
mMotherPosition[0], mMotherPosition[1] - mMotherOvalOffsetY);
}
path.lineTo(mMotherPosition[0], mMotherPosition[1] + mMotherOvalOffsetY);
}
return path;
}
示例14: createPath
import android.graphics.Path; //导入方法依赖的package包/类
/**
* Creates a {@link Path} from an array of instructions constructed by JS
* (see ARTSerializablePath.js). Each instruction starts with a type (see PATH_TYPE_*) followed
* by arguments for that instruction. For example, to create a line the instruction will be
* 2 (PATH_LINE_TO), x, y. This will draw a line from the last draw point (or 0,0) to x,y.
*
* @param data the array of instructions
* @return the {@link Path} that can be drawn to a canvas
*/
private Path createPath(float[] data) {
Path path = new Path();
path.moveTo(0, 0);
int i = 0;
while (i < data.length) {
int type = (int) data[i++];
switch (type) {
case PATH_TYPE_MOVETO:
path.moveTo(data[i++] * mScale, data[i++] * mScale);
break;
case PATH_TYPE_CLOSE:
path.close();
break;
case PATH_TYPE_LINETO:
path.lineTo(data[i++] * mScale, data[i++] * mScale);
break;
case PATH_TYPE_CURVETO:
path.cubicTo(
data[i++] * mScale,
data[i++] * mScale,
data[i++] * mScale,
data[i++] * mScale,
data[i++] * mScale,
data[i++] * mScale);
break;
case PATH_TYPE_ARC:
{
float x = data[i++] * mScale;
float y = data[i++] * mScale;
float r = data[i++] * mScale;
float start = (float) Math.toDegrees(data[i++]);
float end = (float) Math.toDegrees(data[i++]);
boolean clockwise = data[i++] == 0f;
if (!clockwise) {
end = 360 - end;
}
float sweep = start - end;
RectF oval = new RectF(x - r, y - r, x + r, y + r);
path.addArc(oval, start, sweep);
break;
}
default:
throw new JSApplicationIllegalArgumentException(
"Unrecognized drawing instruction " + type);
}
}
return path;
}
示例15: arcToBezier
import android.graphics.Path; //导入方法依赖的package包/类
/**
* Converts an arc to cubic Bezier segments and records them in p.
*
* @param p The target for the cubic Bezier segments
* @param cx The x coordinate center of the ellipse
* @param cy The y coordinate center of the ellipse
* @param a The radius of the ellipse in the horizontal direction
* @param b The radius of the ellipse in the vertical direction
* @param e1x E(eta1) x coordinate of the starting point of the arc
* @param e1y E(eta2) y coordinate of the starting point of the arc
* @param theta The angle that the ellipse bounding rectangle makes with horizontal plane
* @param start The start angle of the arc on the ellipse
* @param sweep The angle (positive or negative) of the sweep of the arc on the ellipse
*/
private static void arcToBezier(Path p,
double cx,
double cy,
double a,
double b,
double e1x,
double e1y,
double theta,
double start,
double sweep) {
// Taken from equations at: http://spaceroots.org/documents/ellipse/node8.html
// and http://www.spaceroots.org/documents/ellipse/node22.html
// Maximum of 45 degrees per cubic Bezier segment
int numSegments = Math.abs((int) Math.ceil(sweep * 4 / Math.PI));
double eta1 = start;
double cosTheta = Math.cos(theta);
double sinTheta = Math.sin(theta);
double cosEta1 = Math.cos(eta1);
double sinEta1 = Math.sin(eta1);
double ep1x = (-a * cosTheta * sinEta1) - (b * sinTheta * cosEta1);
double ep1y = (-a * sinTheta * sinEta1) + (b * cosTheta * cosEta1);
double anglePerSegment = sweep / numSegments;
for (int i = 0; i < numSegments; i++) {
double eta2 = eta1 + anglePerSegment;
double sinEta2 = Math.sin(eta2);
double cosEta2 = Math.cos(eta2);
double e2x = cx + (a * cosTheta * cosEta2) - (b * sinTheta * sinEta2);
double e2y = cy + (a * sinTheta * cosEta2) + (b * cosTheta * sinEta2);
double ep2x = -a * cosTheta * sinEta2 - b * sinTheta * cosEta2;
double ep2y = -a * sinTheta * sinEta2 + b * cosTheta * cosEta2;
double tanDiff2 = Math.tan((eta2 - eta1) / 2);
double alpha =
Math.sin(eta2 - eta1) * (Math.sqrt(4 + (3 * tanDiff2 * tanDiff2)) - 1) / 3;
double q1x = e1x + alpha * ep1x;
double q1y = e1y + alpha * ep1y;
double q2x = e2x - alpha * ep2x;
double q2y = e2y - alpha * ep2y;
p.cubicTo((float) q1x,
(float) q1y,
(float) q2x,
(float) q2y,
(float) e2x,
(float) e2y);
eta1 = eta2;
e1x = e2x;
e1y = e2y;
ep1x = ep2x;
ep1y = ep2y;
}
}