public SearchModel(float radius, float barLength) { float size = (float) ((2*radius + barLength)/Math.sqrt(2)); float center = radius - size/2; // quadrants bottomRightQuadrant = Bezier.quadrant(radius, 0).offset(center, center); bottomLeftQuadrant = Bezier.quadrant(radius, 90).offset(center, center); topLeftQuadrant = Bezier.quadrant(radius, 180).offset(center, center); topRightQuadrant = Bezier.quadrant(radius, 270).offset(center, center); // handle handle = Bezier.line(0, 0, barLength, 0) .offset(radius, 0) .rotate(0, 0, HANDLE_ANGLE) .offset(center, center); } }
public ArrowModel(float length, float headLength, float stroke) { // top head topHead = Bezier.line(0, 0, -headLength, 0); topHead.offset(stroke/2, 0); topHead.rotate(0, 0, HEAD_ANGLE); topHead.offset(length / 2, 0); // body body = Bezier.line(length / 2, 0, -length / 2, 0); // bottom head bottomHead = Bezier.line(0, 0, -headLength, 0); bottomHead.offset(stroke/2, 0); bottomHead.rotate(0, 0, -HEAD_ANGLE); bottomHead.offset(length / 2, 0); } }
public MyCustomToggleDrawable(Context context) { super(context, 0, R.style.CustomToggleDrawableStyle); float radius = Math.round(getIntrinsicWidth()*0.5f); add(Bezier.quadrant(radius, 0), Bezier.line(radius, radius, radius, -radius)); add(Bezier.quadrant(radius, 90), Bezier.line(-radius, radius, radius, radius)); add(Bezier.quadrant(radius, 180), Bezier.line(-radius, radius, -radius, -radius)); add(Bezier.quadrant(radius, 270), Bezier.line(-radius, -radius, radius, -radius)); } }
/** * Construct a quadrant from a bezier line. * @param radius radius in pixel of the quadrant * @param startDegree start angle, sweep is clockwise * @return a quadrant */ public static Bezier quadrant(float radius, float startDegree) { float dv = (float) ((4f/3f)* tan(PI / 8)) * radius; Bezier bezier = new Bezier(); bezier.p1.set(radius, 0); bezier.p2.set(0, radius); bezier.e1.set(bezier.p1.x, bezier.p1.y + dv); bezier.e2.set(bezier.p2.x + dv, bezier.p2.y); if(startDegree != 0) bezier.rotate(0, 0, startDegree); return bezier; } }
@Override public void draw(Canvas canvas) { final Rect bounds = getBounds(); final boolean isRtl = isLayoutRtl(); final float canvasRotate = lerp(isRtl ? -180 : 0, isRtl ? 0 : 180, mProgress); mPath.rewind(); for(int i = 0; i < mCurrent.size(); i++) { Bezier current = mCurrent.get(i); lerp(mStart.get(i), mEnd.get(i), mCurrent.get(i), mProgress); current.addTo(mPath); } canvas.save(); canvas.translate(bounds.centerX(), bounds.centerY()); if (mSpin) { canvas.rotate(canvasRotate * (isRtl ? -1 : 1)); } else if (isRtl) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
public void rotate(Point center, float angle) { rotate(center.x, center.y, angle); }