private static void squigglyHorizontalPath(Path path, float left, float right, float centerY, float amplitude, float periodDegrees) { path.reset(); float y; path.moveTo(left, centerY); float period = (float) (2 * Math.PI / periodDegrees); for (float x = 0; x <= right - left; x += 1) { y = (float) (amplitude * Math.sin(40 + period * x) + centerY); path.lineTo(left + x, y); } } }
private static Path getTrianglePath(int x1, int y1, int width) { final Path path = new Path(); path.moveTo(x1, y1); path.lineTo(x1 + width, y1); path.lineTo(x1, y1 + width); return path; } }
private void drawSpringUp(Canvas canvas, int viewWidth) { if (mSpringRatio > 0) { float leftX = (viewWidth / 2 - 4 * mBollRadius + mSpringRatio * 3 * mBollRadius); if (mSpringRatio < 0.9) { mPath.reset(); mPath.moveTo(leftX, mBollY); mPath.quadTo(viewWidth / 2, mBollY - mBollRadius * mSpringRatio * 2, viewWidth - leftX, mBollY); canvas.drawPath(mPath, mFrontPaint); } else { canvas.drawCircle(viewWidth / 2, mBollY, mBollRadius, mFrontPaint); } } }
private static Path createQuad(float controlX, float controlY) { final Path path = new Path(); path.moveTo(0.0f, 0.0f); path.quadTo(controlX, controlY, 1.0f, 1.0f); return path; }
private void drawBollTail(Canvas canvas, int viewWidth, float fraction) { if (mShowBollTail) { final float bottom = mHeadHeight + mWaveHeight; final float startY = mBollY + mBollRadius * fraction / 2; final float startX = viewWidth / 2 + (float) Math.sqrt(mBollRadius * mBollRadius * (1 - fraction * fraction / 4)); final float bezier1x = (viewWidth / 2 + (mBollRadius * 3 / 4) * (1 - fraction)); final float bezier2x = bezier1x + mBollRadius; mPath.reset(); mPath.moveTo(startX, startY); mPath.quadTo(bezier1x, bottom, bezier2x, bottom); mPath.lineTo(viewWidth - bezier2x, bottom); mPath.quadTo(viewWidth - bezier1x, bottom, viewWidth - startX, startY); canvas.drawPath(mPath, mFrontPaint); } }
private void drawLinePath(Canvas canvas, float x1, float y1, float x2, float y2, Paint paint){ mPath.reset(); mPath.moveTo(x1, y1); mPath.lineTo(x2, y2); canvas.drawPath(mPath, paint); }
@NonNull private Path generateBoxBodyPath(BoxBody body) { mPath.reset(); mPath.moveTo(body.boxLeft, body.boxCenterBottom); mPath.lineTo(body.boxCenterX, body.boxBottom); mPath.lineTo(body.boxRight, body.boxCenterBottom); mPath.quadTo(body.boxRight + body.boxSideLength / 2 * mReboundPercent, body.boxCenterY, body.boxRight, body.boxCenterTop); mPath.lineTo(body.boxCenterX, body.boxTop); mPath.lineTo(body.boxLeft, body.boxCenterTop); mPath.quadTo(body.boxLeft - body.boxSideLength / 2 * mReboundPercent, body.boxCenterY, body.boxLeft, body.boxCenterBottom); mPath.close(); return mPath; } //</editor-fold>
@Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float h = (Float) valueAnimator.getAnimatedValue(); mWavePath.moveTo(0, 0); mWavePath.quadTo(0.25f * mWidth, 0, 0.333f * mWidth, h * 0.5f); mWavePath.quadTo(mWidth * 0.5f, h * 1.4f, 0.666f * mWidth, h * 0.5f); mWavePath.quadTo(0.75f * mWidth, 0, mWidth, 0); final View thisView = WaveView.this; thisView.postInvalidate(); } });
@Override protected void drawGridLine(Canvas c, float x, float y, Path gridLinePath) { gridLinePath.moveTo(mViewPortHandler.contentRight(), y); gridLinePath.lineTo(mViewPortHandler.contentLeft(), y); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); gridLinePath.reset(); }
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; } }
@Override protected Path linePath(Path p, int i, float[] positions) { p.moveTo(positions[i], mViewPortHandler.contentTop()); p.lineTo(positions[i], mViewPortHandler.contentBottom()); return p; }
/** * Draws the grid line at the specified position using the provided path. * * @param c * @param x * @param y * @param gridLinePath */ protected void drawGridLine(Canvas c, float x, float y, Path gridLinePath) { gridLinePath.moveTo(x, mViewPortHandler.contentBottom()); gridLinePath.lineTo(x, mViewPortHandler.contentTop()); // draw a path because lines don't support dashing on lower android versions c.drawPath(gridLinePath, mGridPaint); gridLinePath.reset(); }
/** * Calculates the path for a grid line. * * @param p * @param i * @param positions * @return */ protected Path linePath(Path p, int i, float[] positions) { p.moveTo(mViewPortHandler.offsetLeft(), positions[i + 1]); p.lineTo(mViewPortHandler.contentRight(), positions[i + 1]); return p; }
public static Path createPath(PointF startPoint, PointF endPoint, PointF cp1, PointF cp2) { Path path = new Path(); path.moveTo(startPoint.x, startPoint.y); if (cp1 != null && cp2 != null && (cp1.length() != 0 || 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; }
public void renderLimitLineLine(Canvas c, LimitLine limitLine, float[] position) { mLimitLineSegmentsBuffer[0] = position[0]; mLimitLineSegmentsBuffer[1] = mViewPortHandler.contentTop(); mLimitLineSegmentsBuffer[2] = position[0]; mLimitLineSegmentsBuffer[3] = mViewPortHandler.contentBottom(); mLimitLinePath.reset(); mLimitLinePath.moveTo(mLimitLineSegmentsBuffer[0], mLimitLineSegmentsBuffer[1]); mLimitLinePath.lineTo(mLimitLineSegmentsBuffer[2], mLimitLineSegmentsBuffer[3]); mLimitLinePaint.setStyle(Paint.Style.STROKE); mLimitLinePaint.setColor(limitLine.getLineColor()); mLimitLinePaint.setStrokeWidth(limitLine.getLineWidth()); mLimitLinePaint.setPathEffect(limitLine.getDashPathEffect()); c.drawPath(mLimitLinePath, mLimitLinePaint); }
@Override protected void drawZeroLine(Canvas c) { int clipRestoreCount = c.save(); mZeroLineClippingRect.set(mViewPortHandler.getContentRect()); mZeroLineClippingRect.inset(-mYAxis.getZeroLineWidth(), 0.f); c.clipRect(mLimitLineClippingRect); // draw zero line MPPointD pos = mTrans.getPixelForValues(0f, 0f); mZeroLinePaint.setColor(mYAxis.getZeroLineColor()); mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth()); Path zeroLinePath = mDrawZeroLinePathBuffer; zeroLinePath.reset(); zeroLinePath.moveTo((float) pos.x - 1, mViewPortHandler.contentTop()); zeroLinePath.lineTo((float) pos.x - 1, mViewPortHandler.contentBottom()); // draw a path because lines don't support dashing on lower android versions c.drawPath(zeroLinePath, mZeroLinePaint); c.restoreToCount(clipRestoreCount); }
/** * Draws the zero line. */ protected void drawZeroLine(Canvas c) { int clipRestoreCount = c.save(); mZeroLineClippingRect.set(mViewPortHandler.getContentRect()); mZeroLineClippingRect.inset(0.f, -mYAxis.getZeroLineWidth()); c.clipRect(mZeroLineClippingRect); // draw zero line MPPointD pos = mTrans.getPixelForValues(0f, 0f); mZeroLinePaint.setColor(mYAxis.getZeroLineColor()); mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth()); Path zeroLinePath = mDrawZeroLinePath; zeroLinePath.reset(); zeroLinePath.moveTo(mViewPortHandler.contentLeft(), (float) pos.y); zeroLinePath.lineTo(mViewPortHandler.contentRight(), (float) pos.y); // draw a path because lines don't support dashing on lower android versions c.drawPath(zeroLinePath, mZeroLinePaint); c.restoreToCount(clipRestoreCount); }
@Test public void testReset() throws Exception { Path path = new Path(); path.moveTo(0, 3); path.lineTo(2, 3); path.quadTo(2, 3, 4, 5); path.reset(); ShadowPath shadowPath = shadowOf(path); List<ShadowPath.Point> points = shadowPath.getPoints(); assertEquals(0, points.size()); }
@Test public void testMoveTo() throws Exception { Path path = new Path(); path.moveTo(2, 3); path.moveTo(3, 4); List<ShadowPath.Point> moveToPoints = shadowOf(path).getPoints(); assertEquals(2, moveToPoints.size()); assertEquals(new ShadowPath.Point(2, 3, MOVE_TO), moveToPoints.get(0)); assertEquals(new ShadowPath.Point(3, 4, MOVE_TO), moveToPoints.get(1)); }
@Test public void test_copyConstructor() throws Exception { Path path = new Path(); path.moveTo(0, 3); path.lineTo(2, 3); path.quadTo(2, 3, 4, 5); Path copiedPath = new Path(path); assertEquals(shadowOf(path).getPoints(), shadowOf(copiedPath).getPoints()); } }