Example usage for android.graphics Path lineTo

List of usage examples for android.graphics Path lineTo

Introduction

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

Prototype

public void lineTo(float x, float y) 

Source Link

Document

Add a line from the last point to the specified point (x,y).

Usage

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;//  ww w .ja va  2s  .  c  o m
    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

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();//from ww  w .  j av a  2s  .c  o  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 w w  w.  j av a2 s . com*/
    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

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();//from  w w  w .  j a  va 2s  . c  o  m

    return outline;
}

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();//from  w  ww .  j  a  v a2  s . com
    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

private static Path gloss(int size) {
    Path gloss = new Path();
    gloss.moveTo(0, size);//from  ww  w . j  a  va2  s. c o  m
    gloss.cubicTo(0, size, size * 3 / 4, size * 3 / 4, size, 0);
    gloss.lineTo(0, 0);
    gloss.close();
    return gloss;
}

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;//ww w  . j  av a2  s  .  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:com.acceleratedio.pac_n_zoom.DrawSVG.java

public static void ld_pth_pnts(ArrayList<Integer[]> pnts, Path path) {

    int pnt_nmbr = pnts.size();
    Integer[] crt_pnt = pnts.get(0);
    path.moveTo(crt_pnt[0], crt_pnt[1]);

    // Loop through the points of a path
    for (int pnt_mbr = 1; pnt_mbr < pnt_nmbr; pnt_mbr += 1) {

        crt_pnt = pnts.get(pnt_mbr);//from  w w  w .  jav  a2  s  .  c  om
        path.lineTo(crt_pnt[0], crt_pnt[1]);
    }
}

From source file:Main.java

private static void arcQuadTo(Path pathForTurn, double angle0, float radius0, double angle, float radius,
        double angle2, float radius2, float dl, float cx, float cy) {
    float X0 = getProjX(angle0, cx, cy, radius0);
    float Y0 = getProjY(angle0, cx, cy, radius0);
    float X = getProjX(angle, cx, cy, radius);
    float Y = getProjY(angle, cx, cy, radius);
    float X2 = getProjX(angle2, cx, cy, radius2);
    float Y2 = getProjY(angle2, cx, cy, radius2);
    float l2 = (float) Math.sqrt((X - X2) * (X - X2) + (Y - Y2) * (Y - Y2));
    float l0 = (float) Math.sqrt((X - X0) * (X - X0) + (Y - Y0) * (Y - Y0));
    float proc2 = (float) (dl / l2);
    float proc = (float) (dl / l0);
    pathForTurn.lineTo(X0 * proc + X * (1 - proc), Y0 * proc + Y * (1 - proc));
    pathForTurn.quadTo(X, Y, X2 * proc2 + X * (1 - proc2), Y2 * proc2 + Y * (1 - proc2));
}

From source file:ee.ioc.phon.android.speak.Utils.java

static Bitmap bytesToBitmap(byte[] byteBuffer, int w, int h, int startPosition, int endPosition) {
    final ShortBuffer waveBuffer = ByteBuffer.wrap(byteBuffer).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
    final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    final Canvas c = new Canvas(b);
    final Paint paint = new Paint();
    paint.setColor(0xFFFFFFFF); // 0xAARRGGBB
    paint.setAntiAlias(true);//from   ww  w . j a va2  s.c o  m
    paint.setStyle(Paint.Style.STROKE);
    paint.setAlpha(80);

    final PathEffect effect = new CornerPathEffect(3);
    paint.setPathEffect(effect);

    final int numSamples = waveBuffer.remaining();
    int endIndex;
    if (endPosition == 0) {
        endIndex = numSamples;
    } else {
        endIndex = Math.min(endPosition, numSamples);
    }

    int startIndex = startPosition - 2000; // include 250ms before speech
    if (startIndex < 0) {
        startIndex = 0;
    }
    final int numSamplePerWave = 200; // 8KHz 25ms = 200 samples
    final float scale = 10.0f / 65536.0f;

    final int count = (endIndex - startIndex) / numSamplePerWave;
    final float deltaX = 1.0f * w / count;
    int yMax = h / 2;
    Path path = new Path();
    c.translate(0, yMax);
    float x = 0;
    path.moveTo(x, 0);
    for (int i = 0; i < count; i++) {
        final int avabs = getAverageAbs(waveBuffer, startIndex, i, numSamplePerWave);
        int sign = ((i & 01) == 0) ? -1 : 1;
        final float y = Math.min(yMax, avabs * h * scale) * sign;
        path.lineTo(x, y);
        x += deltaX;
        path.lineTo(x, y);
    }
    if (deltaX > 4) {
        paint.setStrokeWidth(2);
    } else {
        paint.setStrokeWidth(Math.max(0, (int) (deltaX - .05)));
    }
    c.drawPath(path, paint);
    return b;
}