Example usage for com.badlogic.gdx.graphics Pixmap drawCircle

List of usage examples for com.badlogic.gdx.graphics Pixmap drawCircle

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Pixmap drawCircle.

Prototype

public void drawCircle(int x, int y, int radius) 

Source Link

Document

Draws a circle outline with the center at x,y and a radius using the current color and stroke width.

Usage

From source file:es.eucm.ead.editor.view.scene.SimpleSceneViewer.java

License:Open Source License

private void initTextures() {
    Pixmap p = new Pixmap(10, 10, Pixmap.Format.RGBA8888);
    p.setColor(Color.GREEN);//w w w  .j  av  a  2  s.co  m
    p.fillCircle(5, 5, 4);
    p.setColor(Color.DARK_GRAY);
    p.drawCircle(5, 5, 4);

    circle = new Texture(p);
    p.dispose();
    selectionMatrix.translate(-5f, -5.0f, 0f);

    p = new Pixmap(1, 5, Pixmap.Format.RGB888);
    vLine = new Texture(p);
    p.dispose();

    p = new Pixmap(5, 1, Pixmap.Format.RGB888);
    hLine = new Texture(p);
    p.dispose();
}

From source file:es.eucm.ead.engine.assets.drawables.shapes.GdxCircleShape.java

License:Open Source License

@Override
protected Pixmap generatePixmap() {
    EAdPaint paint = descriptor.getPaint();
    EAdFill fill = paint.getFill();//from w w  w  .j  ava 2s.  co  m
    EAdFill border = paint.getBorder();
    int borderWidth = paint.getBorderWidth();
    int size = descriptor.getRadius() * 2 + borderWidth * 2 + 1;
    int center = size / 2;

    Pixmap pixmap = new Pixmap(size, size, Pixmap.Format.RGBA8888);
    pixmapContains = new Pixmap(size, size, Pixmap.Format.RGBA8888);
    pixmapContains.setColor(0, 0, 0, 1);
    pixmapContains.fillCircle(center, center, descriptor.getRadius() + borderWidth);

    ColorFill c = ColorFill.TRANSPARENT;
    if (border != null) {
        if (border instanceof ColorFill) {
            c = (ColorFill) border;

        } else if (border instanceof LinearGradientFill) {
            LinearGradientFill l = (LinearGradientFill) border;
            c = l.getColor1();
        }

        pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f,
                c.getAlpha() / 255.0f);
        pixmap.drawCircle(center, center, descriptor.getRadius() + borderWidth);
    }

    if (fill instanceof ColorFill) {
        c = (ColorFill) fill;
        pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f,
                c.getAlpha() / 255.0f);
        pixmap.fillCircle(center, center, descriptor.getRadius());
    } else if (fill instanceof LinearGradientFill) {
        LinearGradientFill l = (LinearGradientFill) fill;
        initGradientParams(l.getColor1(), l.getX0(), l.getY0(), l.getColor2(), l.getX1(), l.getY1());
        int size2 = descriptor.getRadius() * descriptor.getRadius();
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                int s1 = (i - center);
                s1 = s1 * s1;
                int s2 = (j - center);
                s2 = s2 * s2;
                if (s1 + s2 < size2) {
                    setColor(pixmap, i, j);
                    pixmap.drawPixel(i, j);
                }
            }
        }
    }

    return pixmap;
}

From source file:es.eucm.ead.engine.components.renderers.shape.ShapeToPixmap.java

License:Open Source License

/** Creates a circle **/
private Pixmap createCircle(Circle circle) {
    int radius = circle.getRadius();
    int size = radius * 2;
    pixmapHeight = size;//from   w w  w  .  j  ava 2s . co m
    originX = 0;
    originY = 0;
    Pixmap pixmap = new Pixmap(size, size, Format.RGBA8888);
    if (useGradient) {
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < pixmapHeight; j++) {
                if (auxVector.set(i - radius, j - radius).len() <= radius - 1) {
                    setGradientColor(pixmap, i, j);
                    pixmap.drawPixel(i, j);
                }
            }
        }
    } else {
        pixmap.setColor(color1);
        pixmap.fillCircle(radius, radius, radius - 1);
    }

    if (hasBorder) {
        pixmap.setColor(borderColor);
        pixmap.drawCircle(radius, radius, radius - 1);
    }
    return pixmap;
}

From source file:mobi.shad.s3lib.gfx.pixmap.procedural.Object2D.java

License:Apache License

/**
 * @param pixmap// w w  w. jav a 2  s . c  o  m
 * @param xCenter
 * @param yCenter
 * @param xSize
 * @param ySize
 * @param maxIterations
 */
public static void generate(final Pixmap pixmap, int mode, int count, int size, int growth, int randomColor,
        int red, int green, int blue) {

    S3Log.log("Object2D", "mode: " + mode + " count: " + count + " size: " + size);

    int width = pixmap.getWidth();
    int height = pixmap.getHeight();

    if (objectsPosistionX.length != count) {
        objectsPosistionX = new int[count];
        objectsPosistionY = new int[count];
        objectsExpand = new int[count];
        objectsFade = new int[count];
        objectsColor = new float[count][3];

        for (int i = 0; i < count; i++) {
            objectsPosistionX[i] = rnd.nextInt(width);
            objectsPosistionY[i] = rnd.nextInt(height);
            objectsExpand[i] = rnd.nextInt(growth);
            objectsFade[i] = 0;

            if (randomColor > 0) {
                objectsColor[i][0] = rnd.nextInt(256);
                objectsColor[i][1] = rnd.nextInt(256);
                objectsColor[i][2] = rnd.nextInt(256);
            } else {
                objectsColor[i][0] = red;
                objectsColor[i][1] = green;
                objectsColor[i][2] = blue;
            }
        }
    }

    for (int i = 0; i < count; i++) {
        int r = (int) (objectsColor[i][0] * (1.0F - objectsFade[i] / growth));
        int g = (int) (objectsColor[i][1] * (1.0F - objectsFade[i] / growth));
        int b = (int) (objectsColor[i][2] * (1.0F - objectsFade[i] / growth));

        int diameter = size + objectsExpand[i];

        if (objectsExpand[i] < growth) {

            pixmap.setColor(((int) r << 24) | ((int) g << 16) | ((int) b << 8) | 255);

            int offset = diameter / 2;

            switch (mode) {
            default:
                pixmap.drawCircle(objectsPosistionX[i] - offset, objectsPosistionY[i] - offset, diameter);
                break;
            case 1:
                pixmap.fillCircle(objectsPosistionX[i] - offset, objectsPosistionY[i] - offset, diameter);
                break;
            case 2:
                pixmap.drawRectangle(objectsPosistionX[i] - offset, objectsPosistionY[i] - offset, diameter,
                        diameter);
                break;
            case 3:
                pixmap.fillRectangle(objectsPosistionX[i] - offset, objectsPosistionY[i] - offset, diameter,
                        diameter);
                break;
            case 4:
                pixmap.drawCircle(objectsPosistionX[i] - offset, objectsPosistionY[i] - offset, diameter);
                pixmap.drawCircle(objectsPosistionX[i] - offset + diameter / 4 - diameter / 8,
                        objectsPosistionY[i] - offset + diameter / 3, diameter / 4);
                pixmap.drawCircle(objectsPosistionX[i] - offset + (int) (diameter * 0.75F) - diameter / 8,
                        objectsPosistionY[i] - offset + diameter / 3, diameter / 4);
                pixmap.drawCircle(objectsPosistionX[i] - offset + diameter / 4,
                        objectsPosistionY[i] - offset + diameter / 3, diameter / 8);
                pixmap.drawCircle(objectsPosistionX[i] - offset + (int) (diameter * 0.75F),
                        objectsPosistionY[i] - offset + diameter / 3, diameter / 8);
                break;
            }
        }

        objectsExpand[i] += 2;
        objectsFade[i] += 2;
        if (objectsFade[i] >= growth) {
            objectsFade[i] = growth;
        }

        if ((objectsExpand[i] < growth) || (rnd.nextInt(100) >= 10)) {
            continue;
        }
        objectsPosistionX[i] = rnd.nextInt(width);
        objectsPosistionY[i] = rnd.nextInt(height);
        objectsExpand[i] = 0;
        objectsFade[i] = 0;
    }
}