com.juankysoriano.rainbow.core.drawing.Modes Java Examples

The following examples show how to use com.juankysoriano.rainbow.core.drawing.Modes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Perform initialization specific to curveVertex(), and handle standard
 * error modes. Can be overridden by subclasses that need the flexibility.
 */
void curveVertexCheck(Modes.Shape shape) {
    if (shape != POLYGON) {
        throw new RuntimeException("You must use beginShape() or " + "beginShape(POLYGON) before curveVertex()");
    }
    // to improve code init time, allocate on first use.
    if (curveVertices == null) {
        curveVertices = new float[128][3];
    }

    if (curveVertexCount == curveVertices.length) {
        // Can't use Imagine.expand() cuz it doesn't do the copy
        // properly
        float[][] temp = new float[curveVertexCount << 1][3];
        System.arraycopy(curveVertices, 0, temp, 0, curveVertexCount);
        curveVertices = temp;
    }
    curveInitCheck();
}
 
Example #2
Source File: RainbowImage.java    From rainbow with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Copies area of one image into another PImage object.
 *
 * @see RainbowImage#blendColor(int, int, Modes.Blend)
 */
public void blend(RainbowImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, Modes.Blend mode) {
    int sx2 = sx + sw;
    int sy2 = sy + sh;
    int dx2 = dx + dw;
    int dy2 = dy + dh;

    loadPixels();
    if (src == this) {
        if (intersect(sx, sy, sx2, sy2, dx, dy, dx2, dy2)) {
            blit_resize(get(sx, sy, sx2 - sx, sy2 - sy), 0, 0, sx2 - sx - 1, sy2 - sy - 1, pixels, width, height, dx, dy, dx2, dy2, mode);
        } else {
            blit_resize(src, sx, sy, sx2, sy2, pixels, width, height, dx, dy, dx2, dy2, mode);
        }
    } else {
        src.loadPixels();
        blit_resize(src, sx, sy, sx2, sy2, pixels, width, height, dx, dy, dx2, dy2, mode);
    }
    updatePixels();
}
 
Example #3
Source File: FlowerDrawer.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
public void paintFlowerFor(Branch branch) {
    if (hasFlowersToPaint()) {
        float flowerSize = getFlowerSize();
        float rotation = RainbowMath.random(RainbowMath.QUARTER_PI);
        rainbowDrawer.tint(WHITE);
        rainbowDrawer.imageMode(Modes.Draw.CENTER);
        rainbowDrawer.pushMatrix();
        rainbowDrawer.translate(branch.getX(), branch.getY());
        rainbowDrawer.rotate(rotation);
        flipHorizontallyIfLuck();
        rainbowDrawer.image(getRandomFlower(), 0, 0, flowerSize, flowerSize);
        rainbowDrawer.popMatrix();
    }
}
 
Example #4
Source File: RainbowGraphics2D.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void strokeJoin(Modes.Stroke.Join mode) {
    super.strokeJoin(mode);

    if (strokeJoin == Modes.Stroke.Join.MITER) {
        strokePaint.setStrokeJoin(Paint.Join.MITER);
    } else if (strokeJoin == Modes.Stroke.Join.ROUND) {
        strokePaint.setStrokeJoin(Paint.Join.ROUND);
    } else if (strokeJoin == Modes.Stroke.Join.BEVEL) {
        strokePaint.setStrokeJoin(Paint.Join.BEVEL);
    }
}
 
Example #5
Source File: RainbowGraphics2D.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void strokeCap(Modes.Stroke.Cap mode) {
    super.strokeCap(mode);

    if (strokeCap == Modes.Stroke.Cap.ROUND) {
        strokePaint.setStrokeCap(Paint.Cap.ROUND);
    } else if (strokeCap == Modes.Stroke.Cap.SQUARE) {
        strokePaint.setStrokeCap(Paint.Cap.SQUARE);
    } else if (strokeCap == Modes.Stroke.Cap.BUTT) {
        strokePaint.setStrokeCap(Paint.Cap.BUTT);
    }
}
 
Example #6
Source File: RainbowGraphics2D.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void endPolygonShape(Modes.Shape mode) {
    if (!path.isEmpty()) {
        if (mode == CLOSE) {
            path.close();
        }
        drawPath();
    }
}
 
Example #7
Source File: RainbowGraphics2D.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void endShape(Modes.Shape mode) {
    if (shapeMode == POINTS && stroke && vertexCount > 0) {
        endPointsShape();
    } else if (shapeMode == POLYGON) {
        endPolygonShape(mode);
    }
    shapeMode = UNDEFINED;
}
 
Example #8
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void colorMode(Modes.Image mode, float maxX, float maxY, float maxZ, float maxA) {
    colorMode = mode;

    colorModeX = maxX; // still needs to be set for hsb
    colorModeY = maxY;
    colorModeZ = maxZ;
    colorModeA = maxA;

    colorModeScale = ((maxA != 1) || (maxX != maxY) || (maxY != maxZ) || (maxZ != maxA));
    colorModeDefault = (colorMode == RGB) && (colorModeA == 255) && (colorModeX == 255) && (colorModeY == 255) && (colorModeZ == 255);
}
 
Example #9
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The mode can only be set to CORNERS, CORNER, and CENTER.
 * <p/>
 * Support for CENTER was added in release 0146.
 */
public void imageMode(Modes.Draw mode) {
    if ((mode == CORNER) || (mode == CORNERS) || (mode == CENTER)) {
        imageDrawMode = mode;
    } else {
        String msg = "imageMode() only works with CORNER, CORNERS, or CENTER";
        throw new RuntimeException(msg);
    }
}
 
Example #10
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void arc(float a, float b, float c, float d, float start, float stop, Modes.Arc mode) {
    float x = a;
    float y = b;
    float w = c;
    float h = d;

    if (ellipseMode == CORNERS) {
        w = c - a;
        h = d - b;

    } else if (ellipseMode == RADIUS) {
        x = a - c;
        y = b - d;
        w = c * 2;
        h = d * 2;

    } else if (ellipseMode == CENTER) {
        x = a - c / 2f;
        y = b - d / 2f;
    }

    // make sure the loop will exit before starting while
    if (!Float.isInfinite(start) && !Float.isInfinite(stop)) {
        // ignore equal and degenerate cases
        if (stop > start) {
            // make sure that we're starting at a useful point
            while (start < 0) {
                start += RainbowMath.TWO_PI;
                stop += RainbowMath.TWO_PI;
            }

            if (stop - start > RainbowMath.TWO_PI) {
                start = 0;
                stop = RainbowMath.TWO_PI;
            }
            arcImpl(x, y, w, h, start, stop, mode);
        }
    }
}
 
Example #11
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void bezierVertexCheck(Modes.Shape shape, int vertexCount) {
    if (shape == UNDEFINED || shape != POLYGON) {
        throw new RuntimeException("beginShape() or beginShape(POLYGON) " + "must be used before bezierVertex() or quadraticVertex()");
    }
    if (vertexCount == 0) {
        throw new RuntimeException("vertex() must be used at least once" + "before bezierVertex() or quadraticVertex()");
    }
}
 
Example #12
Source File: RainbowBitmapUtils.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Bitmap getBitmap(Uri uri, int reqWidth, int reqHeight, Modes.LoadMode mode) {
    try {
        if (mode == Modes.LoadMode.LOAD_CENTER_CROP) {
            return Picasso.get().load(uri).resize(reqWidth, reqHeight).centerCrop().get();
        } else if (mode == Modes.LoadMode.LOAD_CENTER_INSIDE) {
            return Picasso.get().load(uri).resize(reqWidth, reqHeight).centerInside().get();
        } else if (mode == Modes.LoadMode.LOAD_ORIGINAL_SIZE) {
            return Picasso.get().load(uri).get();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #13
Source File: RainbowBitmapUtils.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Bitmap getBitmap(File file, int reqWidth, int reqHeight, Modes.LoadMode mode) {
    try {
        if (mode == Modes.LoadMode.LOAD_CENTER_CROP) {
            return Picasso.get().load(file).resize(reqWidth, reqHeight).centerCrop().get();
        } else if (mode == Modes.LoadMode.LOAD_CENTER_INSIDE) {
            return Picasso.get().load(file).resize(reqWidth, reqHeight).centerInside().get();
        } else if (mode == Modes.LoadMode.LOAD_ORIGINAL_SIZE) {
            return Picasso.get().load(file).get();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #14
Source File: FlowerDrawerTest.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testThatInitDoesLoadImageForEveryImageOnFlower() {
    flowerDrawer.init();

    for (Integer flowerImageId : flowerToPaint.getFlowerLeafRes()) {
        verify(rainbowDrawer).loadImage(flowerImageId, Modes.LoadMode.LOAD_ORIGINAL_SIZE, flowerDrawer);
    }
}
 
Example #15
Source File: InkPerformerTest.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testThatInitConfiguresRainbowDrawer() {
    inkPerformer.init();

    verify(rainbowDrawer).noStroke();
    verify(rainbowDrawer).smooth();
    verify(rainbowDrawer).loadImage(R.drawable.brush_ink, Modes.LoadMode.LOAD_ORIGINAL_SIZE, inkPerformer);
}
 
Example #16
Source File: RainbowBitmapUtils.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Bitmap getBitmap(String path, int reqWidth, int reqHeight, Modes.LoadMode mode) {
    try {
        if (mode == Modes.LoadMode.LOAD_CENTER_CROP) {
            return Picasso.get().load(path).resize(reqWidth, reqHeight).centerCrop().get();
        } else if (mode == Modes.LoadMode.LOAD_CENTER_INSIDE) {
            return Picasso.get().load(path).resize(reqWidth, reqHeight).centerInside().get();
        } else if (mode == Modes.LoadMode.LOAD_ORIGINAL_SIZE) {
            return Picasso.get().load(path).get();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #17
Source File: RainbowBitmapUtils.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Bitmap getBitmap(int resId, int reqWidth, int reqHeight, Modes.LoadMode mode) {
    try {
        if (mode == Modes.LoadMode.LOAD_CENTER_CROP) {
            return Picasso.get().load(resId).resize(reqWidth, reqHeight).centerCrop().get();
        } else if (mode == Modes.LoadMode.LOAD_CENTER_INSIDE) {
            return Picasso.get().load(resId).resize(reqWidth, reqHeight).centerInside().get();
        } else if (mode == Modes.LoadMode.LOAD_ORIGINAL_SIZE) {
            return Picasso.get().load(resId).get();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #18
Source File: World.java    From MaterialLife with GNU General Public License v2.0 5 votes vote down vote up
public void loadWorldFrom(final Uri image) {
    gameOfLife.clear();
    SCHEDULER.scheduleNow(new Runnable() {
        @Override
        public void run() {
            getRainbowDrawer().loadImage(image, Modes.LoadMode.LOAD_CENTER_CROP, World.this);
        }
    });
}
 
Example #19
Source File: RainbowLineCirclesSketch.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onPointDetected(float px, float py, float x, float y) {
    getRainbowDrawer().stroke(0, 30);
    getRainbowDrawer().fill(0, 0);
    getRainbowDrawer().ellipseMode(Modes.Draw.CENTER);
    getRainbowDrawer().ellipse(x, y, 200, 200);
}
 
Example #20
Source File: InkPerformer.java    From Zen with GNU General Public License v2.0 5 votes vote down vote up
private void paintDropWithImage(float x, float y) {
    rainbowDrawer.tint(inkDrop.getBrushColor().color());
    rainbowDrawer.imageMode(Modes.Draw.CENTER);

    rainbowDrawer.pushMatrix();
    rainbowDrawer.translate(x, y);
    rainbowDrawer.rotate(RainbowMath.random(RainbowMath.TWO_PI));
    rainbowDrawer.image(image, 0, 0, inkDrop.getRadius(), inkDrop.getRadius());
    rainbowDrawer.popMatrix();
}
 
Example #21
Source File: RainbowBlobDetection.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onSketchSetup() {
    super.onSketchSetup();
    getRainbowDrawer().smooth();
    getRainbowDrawer().noFill();
    getRainbowDrawer().background(0, 0, 0);
    getRainbowDrawer().loadImage(
            R.drawable.winnie,
            (getWidth() / RESIZE_FACTOR),
            (getHeight() / RESIZE_FACTOR),
            Modes.LoadMode.LOAD_CENTER_CROP,
            new RainbowImage.LoadPictureListener() {

                @Override
                public void onLoadSucceed(RainbowImage image) {
                    rainbowImage = image;
                    mediaPlayer.start();
                    blobDetection = new BlobDetection(rainbowImage);
                    resetThreshold();
                    startNextBunchDetection();
                }

                @Override
                public void onLoadFail() {
                    //no-op
                }
            }
    );
}
 
Example #22
Source File: RainbowGraphics2D.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void beginShape(Modes.Shape mode) {
    shapeMode = mode;
    vertexCount = 0;
    curveVertexCount = 0;
}
 
Example #23
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void colorMode(Modes.Image format, float max) {
    colorMode(format, max, max, max, max);
}
 
Example #24
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void colorMode(Modes.Image mode) {
    colorMode(mode, colorModeX, colorModeY, colorModeZ, colorModeA);
}
 
Example #25
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void strokeCap(Modes.Stroke.Cap mode) {
    strokeCap = mode;
}
 
Example #26
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void strokeJoin(Modes.Stroke.Join mode) {
    strokeJoin = mode;
}
 
Example #27
Source File: RainbowGraphics2D.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void arcImpl(float x, float y, float w, float h, float start, float stop, Modes.Arc mode) {

    if (stop - start >= RainbowMath.TWO_PI) {
        ellipseImpl(x, y, w, h);

    } else {

        start = start * RainbowMath.RAD_TO_DEG;
        stop = stop * RainbowMath.RAD_TO_DEG;

        while (start < 0) {
            start += 360;
            stop += 360;
        }
        if (start > stop) {
            float temp = start;
            start = stop;
            stop = temp;
        }

        float sweep = stop - start;
        rect.set(x, y, x + w, y + h);

        if (mode == Modes.Arc.UNDEFINED) {
            if (fill) {
                canvas.drawArc(rect, start, sweep, true, fillPaint);
            }
            if (stroke) {
                canvas.drawArc(rect, start, sweep, false, strokePaint);
            }
        } else if (mode == Modes.Arc.OPEN) {
            if (fill) {
                showMissingWarning("arc");
            }
            if (stroke) {
                canvas.drawArc(rect, start, sweep, false, strokePaint);
            }
        } else if (mode == Modes.Arc.CHORD) {
            showMissingWarning("arc");

        } else if (mode == Modes.Arc.PIE) {
            if (fill) {
                canvas.drawArc(rect, start, sweep, true, fillPaint);
            }
            if (stroke) {
                canvas.drawArc(rect, start, sweep, true, strokePaint);
            }

        }
    }
}
 
Example #28
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void ellipseMode(Modes.Draw mode) {
    ellipseMode = mode;
}
 
Example #29
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void rectMode(Modes.Draw mode) {
    rectMode = mode;
}
 
Example #30
Source File: RainbowGraphics.java    From rainbow with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void endShape(Modes.Shape mode) {
}