Example usage for android.graphics Path moveTo

List of usage examples for android.graphics Path moveTo

Introduction

In this page you can find the example usage for android.graphics Path moveTo.

Prototype

public void moveTo(float x, float y) 

Source Link

Document

Set the beginning of the next contour to the point (x,y).

Usage

From source file:Main.java

/**
 * Helper method to draw a generic triangle onto the canvas
 * @param canvas the canvas being drawn to
 * @param a point 1//from  ww  w. j a v  a  2 s.c  o m
 * @param b point 2
 * @param c point 3
 */
public static void drawTriangle(Canvas canvas, Point a, Point b, Point c, Paint paint) {

    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(b.x, b.y);
    path.lineTo(c.x, c.y);
    path.lineTo(a.x, a.y);
    path.close();

    canvas.drawPath(path, paint);
}

From source file:Main.java

private static Path drawOutLine() {
    //Draw the outline
    Path outline = new Path();
    outline.moveTo(coord_A[0], coord_A[1]); /*A*/
    outline.lineTo(coord_B[0], coord_B[1]); /*B*/
    outline.lineTo(coord_C[0], coord_C[1]); /*C*/
    outline.lineTo(coord_D[0], coord_D[1]); /*D*/
    outline.lineTo(coord_E[0], coord_E[1]); /*E*/
    outline.lineTo(coord_F[0], coord_F[1]); /*F*/
    outline.lineTo(coord_G[0], coord_G[1]); /*G*/
    outline.lineTo(coord_H[0], coord_H[1]); /*H*/
    outline.lineTo(coord_I[0], coord_I[1]); /*I*/
    outline.lineTo(coord_J[0], coord_J[1]); /*J*/
    outline.moveTo(coord_A[2], coord_A[3]); /*A*/
    outline.lineTo(coord_B[2], coord_B[3]); /*J*/
    outline.lineTo(coord_C[2], coord_C[3]); /*I*/
    outline.lineTo(coord_D[2], coord_D[3]); /*H*/
    outline.lineTo(coord_E[2], coord_E[3]); /*G*/
    outline.lineTo(coord_F[2], coord_F[3]); /*F*/
    outline.lineTo(coord_G[2], coord_G[3]); /*E*/
    outline.lineTo(coord_H[2], coord_H[3]); /*D*/
    outline.lineTo(coord_I[2], coord_I[3]); /*C*/
    outline.lineTo(coord_J[2], coord_J[3]); /*B*/
    outline.close();//w w w . ja v  a  2 s . c o  m

    return outline;
}

From source file:Main.java

private static void drawAntiRoundRect(Canvas canvas, Paint paint, int radius, RectF rect, int direction) {
    if (direction == 1) {
        Path path = new Path();
        path.moveTo(rect.left, rect.top);
        path.lineTo(rect.left, rect.top + radius);
        path.addArc(new RectF(rect.left, rect.top, rect.left + radius * 2, rect.top + radius * 2), 180, 90);
        path.lineTo(rect.left, rect.top);
        path.close();//  w w w. j a  v a  2 s  . co  m
        canvas.drawPath(path, paint);
    } else if (direction == 2) {
        Path path = new Path();
        path.moveTo(rect.right, rect.top);
        path.lineTo(rect.right - radius, rect.top);
        path.addArc(new RectF(rect.right - 2 * radius, rect.top, rect.right, rect.top + radius * 2), 270, 90);
        path.lineTo(rect.right, rect.top);
        path.close();
        canvas.drawPath(path, paint);
    } else if (direction == 3) {
        Path path = new Path();
        path.moveTo(rect.right, rect.bottom);
        path.lineTo(rect.right, rect.bottom - radius);
        path.addArc(new RectF(rect.right - 2 * radius, rect.bottom - 2 * radius, rect.right, rect.bottom), 0,
                90);
        path.lineTo(rect.right, rect.bottom);
        path.close();
        canvas.drawPath(path, paint);
    } else if (direction == 4) {
        Path path = new Path();
        path.moveTo(rect.left, rect.bottom);
        path.lineTo(rect.left + radius, rect.bottom);
        path.addArc(new RectF(rect.left, rect.bottom - 2 * radius, rect.left + 2 * radius, rect.bottom), 90,
                90);
        path.lineTo(rect.left, rect.bottom);
        path.close();
        canvas.drawPath(path, paint);
    }
}

From source file:Main.java

public static void drawWallpaperSelectionFrame(Canvas canvas, RectF cropBounds, float spotX, float spotY,
        Paint p, Paint shadowPaint) {
    float sx = cropBounds.width() * spotX;
    float sy = cropBounds.height() * spotY;
    float cx = cropBounds.centerX();
    float cy = cropBounds.centerY();
    RectF r1 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
    float temp = sx;
    sx = sy;//from ww w.j av a  2  s. c o  m
    sy = temp;
    RectF r2 = new RectF(cx - sx / 2, cy - sy / 2, cx + sx / 2, cy + sy / 2);
    canvas.save();
    canvas.clipRect(cropBounds);
    canvas.clipRect(r1, Region.Op.DIFFERENCE);
    canvas.clipRect(r2, Region.Op.DIFFERENCE);
    canvas.drawPaint(shadowPaint);
    canvas.restore();
    Path path = new Path();
    path.moveTo(r1.left, r1.top);
    path.lineTo(r1.right, r1.top);
    path.moveTo(r1.left, r1.top);
    path.lineTo(r1.left, r1.bottom);
    path.moveTo(r1.left, r1.bottom);
    path.lineTo(r1.right, r1.bottom);
    path.moveTo(r1.right, r1.top);
    path.lineTo(r1.right, r1.bottom);
    path.moveTo(r2.left, r2.top);
    path.lineTo(r2.right, r2.top);
    path.moveTo(r2.right, r2.top);
    path.lineTo(r2.right, r2.bottom);
    path.moveTo(r2.left, r2.bottom);
    path.lineTo(r2.right, r2.bottom);
    path.moveTo(r2.left, r2.top);
    path.lineTo(r2.left, r2.bottom);
    canvas.drawPath(path, p);
}

From source file:Main.java

static Path getWavePath(float width, float height, float amplitude, float shift, float divide) {
    Path path = new Path();
    float quadrant = height - amplitude;
    float x, y;/*from   w  w w.  j a  v a2 s . c  om*/
    path.moveTo(0, 0);
    path.lineTo(0, quadrant);
    for (int i = 0; i < width + 10; i = i + 10) {
        x = (float) i;
        y = quadrant + amplitude * (float) Math.sin(((i + 10) * Math.PI / 180) / divide + shift);
        path.lineTo(x, y);
    }
    path.lineTo(width, 0);
    path.close();
    return path;
}

From source file:Main.java

/**
 * Returns a path with a given set of peeks in a 'randomly' handrawn style
 * /*from   w ww. j a v a  2s  .c o  m*/
 * @param peek_x
 *            array of X locations of the peeks
 * @param peek_y
 *            array of Y locations of the peeks
 * @return constructed path
 */
public static Path peeks(float[] peek_x, float[] peek_y, float offset) {
    final Path p = new Path();

    p.moveTo(-offset, 0);

    float diff = 0;
    float cdiff = 0;
    int cp = 0;
    for (float x = -offset + RESOLUTION; x < 1 + offset; x += RESOLUTION) {

        if (x >= peek_x[cp]) {
            if (cp == peek_x.length - 1) {
                diff = 0;
                cdiff = 0;
            } else {
                diff = (peek_y[cp] - peek_y[cp + 1]) / ((peek_x[cp + 1] - peek_x[cp]) / RESOLUTION);
                if (diff == 0) {
                    cdiff = 0;
                }
                ++cp;
            }
        }
        cdiff += diff;

        float to_y = cdiff
                + (randomizer.nextBoolean() ? 1 : -1) * randomizer.nextFloat() * (diff == 0 ? 0.003f : 0.01f);
        if (to_y < -MAX) {
            to_y = 0;
        }
        p.lineTo(x, -to_y);
    }

    p.lineTo(1 + offset, 0);

    return p;
}

From source file:Main.java

public static void computeCircleFailedSymbolPath(RectF contentRect, int sideLength, Path failedSymbolPath1,
        Path failedSymbolPath2) {
    float padding = sideLength * 0.3f;
    failedSymbolPath1.moveTo(contentRect.left + padding, contentRect.top + padding);
    failedSymbolPath1.quadTo(contentRect.left + padding, contentRect.top + padding, contentRect.right - padding,
            contentRect.bottom - padding);

    failedSymbolPath2.moveTo(contentRect.right - padding, contentRect.top + padding);
    failedSymbolPath2.quadTo(contentRect.right - padding, contentRect.top + padding, contentRect.left + padding,
            contentRect.bottom - padding);
}

From source file:Main.java

public static void drawBorder(int width, int height, Canvas canvas, Paint paint, Path workingPath) {

    paint.setStyle(Paint.Style.STROKE);
    workingPath.reset();/*www.  jav  a 2s  .  c om*/
    workingPath.moveTo(0, 0);
    workingPath.lineTo(width, 0);
    workingPath.lineTo(width, height);
    workingPath.lineTo(0, height);
    workingPath.lineTo(0, 0);
    workingPath.close();

    canvas.drawPath(workingPath, paint);

}

From source file:Main.java

public static Path createCommentShape(int x, int y, int width, int height, boolean no_bottom) {
    Path gp = new Path();
    int arc = 4;/*from   w  ww  .  j av  a  2s  .c o m*/

    if (no_bottom == true) {
        gp.moveTo(0, height);
        gp.lineTo(0, 5 + arc);
    } else {
        gp.moveTo(0, 5 + arc);
    }

    gp.quadTo(0, 5, arc, 5);
    gp.lineTo(15, 5);
    gp.lineTo(20, 0);
    gp.lineTo(25, 5);
    gp.lineTo(width - arc, 5);
    gp.quadTo(width, 5, width, 5 + arc);
    gp.lineTo(width, height - arc);

    if (no_bottom) {
        gp.lineTo(width, height);
    } else {
        gp.quadTo(width, height, width - arc, height);
        gp.lineTo(arc, height);
        gp.quadTo(0, height, 0, height - arc);
        gp.lineTo(0, 5 + arc);
    }

    return gp;
}

From source file:Main.java

public static void addBezierArcToPath(@NonNull Path path, @NonNull PointF center, @NonNull PointF start,
        @NonNull PointF end, boolean moveToStart) {
    if (moveToStart) {
        path.moveTo(start.x, start.y);
    }//from   www .java2s.com
    if (start.equals(end)) {
        return;
    }

    final double ax = start.x - center.x;
    final double ay = start.y - center.y;
    final double bx = end.x - center.x;
    final double by = end.y - center.y;
    final double q1 = ax * ax + ay * ay;
    final double q2 = q1 + ax * bx + ay * by;
    final double k2 = 4d / 3d * (sqrt(2d * q1 * q2) - q2) / (ax * by - ay * bx);
    final float x2 = (float) (center.x + ax - k2 * ay);
    final float y2 = (float) (center.y + ay + k2 * ax);
    final float x3 = (float) (center.x + bx + k2 * by);
    final float y3 = (float) (center.y + by - k2 * bx);

    path.cubicTo(x2, y2, x3, y3, end.x, end.y);
}