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

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

Introduction

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

Prototype

public void drawPixel(int x, int y) 

Source Link

Document

Draws a pixel at the given location with the current color.

Usage

From source file:at.tugraz.ist.catroid.content.Costume.java

License:Open Source License

protected Pixmap adjustBrightness(Pixmap currentPixmap) {
    Pixmap newPixmap = new Pixmap(currentPixmap.getWidth(), currentPixmap.getHeight(),
            currentPixmap.getFormat());//w  w  w  .  j  a  v a 2  s  . c  o m
    for (int y = 0; y < currentPixmap.getHeight(); y++) {
        for (int x = 0; x < currentPixmap.getWidth(); x++) {
            int pixel = currentPixmap.getPixel(x, y);
            int r = (int) (((pixel >> 24) & 0xff) + (255 * (brightnessValue - 1)));
            int g = (int) (((pixel >> 16) & 0xff) + (255 * (brightnessValue - 1)));
            int b = (int) (((pixel >> 8) & 0xff) + (255 * (brightnessValue - 1)));
            int a = pixel & 0xff;

            if (r > 255) {
                r = 255;
            } else if (r < 0) {
                r = 0;
            }
            if (g > 255) {
                g = 255;
            } else if (g < 0) {
                g = 0;
            }
            if (b > 255) {
                b = 255;
            } else if (b < 0) {
                b = 0;
            }

            newPixmap.setColor(r / 255f, g / 255f, b / 255f, a / 255f);
            newPixmap.drawPixel(x, y);
        }
    }
    currentPixmap.dispose();
    return newPixmap;
}

From source file:base.Engine.java

License:Open Source License

public static Pixmap generatePatternPixmap(PatternEntry basedOn, Color color) {
    Pixmap returnPixmap = new Pixmap(basedOn.getWrapper().getW(), basedOn.getWrapper().getH(),
            Pixmap.Format.RGBA8888);
    returnPixmap.setColor(Color.rgba8888(0, 0, 0, 0));
    returnPixmap.fill();/*w ww . j a  v a  2  s . c om*/

    returnPixmap.setColor(Color.DARK_GRAY);
    returnPixmap.drawPixel(0, 0);

    returnPixmap.setColor(color);

    for (int x = 0; x < basedOn.getWrapper().getW(); x++)
        for (int y = 0; y < basedOn.getWrapper().getH(); y++)
            if (basedOn.getCells()[x][y] != 0)
                returnPixmap.drawPixel(x, y);

    return returnPixmap;
}

From source file:com.cyphercove.doublehelix.PowerLUT.java

License:Apache License

/** W power will be in luminance, and H power will be in alpha**/
public PowerLUT(float powerW, float intensityW, float powerH, float intensityH, int width, int height) {

    Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
    for (int i = 0; i < width; i++) {
        float valueW = (float) Math.pow((float) i / width, powerW) * intensityW;
        for (int j = 0; j < height; j++) {
            float valueH = (float) Math.pow((float) j / height, powerH) * intensityH;
            pixmap.setColor(valueW, valueH, 1.0f, 1.0f);
            pixmap.drawPixel(i, j);
        }//from  ww w  .j a va 2 s .  c o m
    }

    PixmapTextureData data = new PixmapTextureData(pixmap, Format.RGBA8888, false, false, true);

    texture = new Texture(data);
    texture.setWrap(TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}

From source file:com.github.skittishSloth.openSkies.maps.VoronoiTestScreen.java

public VoronoiTestScreen() {
    final int tileSize = 1;
    final int width = Gdx.graphics.getWidth() / tileSize;
    final int height = Gdx.graphics.getHeight() / tileSize;

    final int numSites = 2000;

    map = VoronoiMap.generateRandom(numSites, width, height);
    final Collection<Site> sites = map.getSites();
    bfMap = new BruteForceVoronoiMap(width, height, tileSize, sites);

    final float[][] landProbability = PerlinNoiseGenerator.generatePerlinNoise(width, height, 2);

    final Pixmap pm = new Pixmap(width, height, Pixmap.Format.RGBA8888);
    pm.setColor(Color.BLACK);/*from  w  w  w  .j  a v a  2  s .co m*/
    pm.fill();

    final Map<Site, Cell> cells = bfMap.buildCells(landProbability);
    for (final Site site : sites) {
        final Cell cell = cells.get(site);
        if (cell == null) {
            System.err.println("Cell was null for site " + site.getX() + ", " + site.getY());
            continue;
        }

        final boolean landCell = cell.isLand();
        final Color cellColor;
        if (landCell) {
            cellColor = Elevation.PLAINS.getColor();
        } else {
            cellColor = Elevation.WATER.getColor();
        }

        pm.setColor(cellColor);
        final List<VoronoiTile> tiles = cell.getTiles();
        for (final VoronoiTile tile : tiles) {
            final int x = tile.getX();
            final int y = tile.getY();
            pm.drawPixel(x, y);
        }
    }

    pm.setColor(Color.BLACK);
    for (final Site site : sites) {
        final Cell cell = cells.get(site);
        if (cell == null) {
            System.err.println("Cell was null for site " + site.getX() + ", " + site.getY());
            continue;
        }

        final Polygon polygon = cell.calculateConvexHull();
        final float[] vertices = polygon.getVertices();
        final boolean hasCornerPoint = cell.hasCornerPoint();

        final List<Point> verticesPoints = new ArrayList<Point>();
        for (int i = 0; i < vertices.length - 1;) {
            final int x = Math.round(vertices[i++]);
            final int y = Math.round(vertices[i++]);
            if ((x == 0) && (y == 0)) {
                if (!hasCornerPoint) {
                    continue;
                }
            }
            final Point p = new Point(x, y);
            verticesPoints.add(p);
        }

        final int numPoints = verticesPoints.size();

        for (int i = 0; i < numPoints - 1;) {
            final Point p1 = verticesPoints.get(i++);
            final Point p2 = verticesPoints.get(i++);
            pm.drawLine(p1.x, p1.y, p2.x, p2.y);
        }
    }

    pm.setColor(Color.WHITE);
    for (final Site site : sites) {
        final int x = site.getX();
        final int y = site.getY();
        pm.drawPixel(x, y);
    }

    mapTexture = new Texture(pm);
    pm.dispose();

    batch = new SpriteBatch();
}

From source file:com.mikeduvall.GameObject.java

License:Apache License

void drawByteBufferOnPixMap(Pixmap pixmap, PaletteFile paletteFile, ByteBuffer byteBuffer0, int width,
        int height) {

    int currentIndex = 0;

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (!byteBuffer0.hasRemaining()) {
                continue;
            }//from  w  w  w .  j av a  2  s . co  m

            byte nextByte = byteBuffer0.get(currentIndex);
            if (nextByte != 0) {
                int index = Byte.toUnsignedInt(nextByte);

                index = mapColorIndex(index);
                PaletteEntry paletteEntry = paletteFile.getPaletteEntries().get(index);

                float red = paletteEntry.getRed() / 63.0f;
                float green = paletteEntry.getGreen() / 63.0f;
                float blue = paletteEntry.getBlue() / 63.0f;

                Color color = new Color(red, green, blue, 1);

                pixmap.setColor(color);

                pixmap.drawPixel(x, y);

            }
            currentIndex++;
        }
    }
}

From source file:com.ray3k.skincomposer.utils.Utils.java

License:Open Source License

/**
 * Does not dispose pixmap/*from   w w  w .  j a va  2 s .co m*/
 * @param pixmap
 * @return 
 */
public static Pixmap tintPixmap(Pixmap pixmap, Color color) {
    Color tempColor = new Color();
    for (int y = 0; y < pixmap.getHeight(); y++) {
        for (int x = 0; x < pixmap.getWidth(); x++) {
            tempColor.set(pixmap.getPixel(x, y));
            float a = tempColor.a;
            tempColor.mul(color);
            tempColor.a = a;
            pixmap.setColor(tempColor);
            pixmap.drawPixel(x, y);
            tempColor.set(pixmap.getPixel(x, y));
        }
    }
    return pixmap;
}

From source file:de.gebatzens.meteva.GScout.java

License:Open Source License

@Override
public void create() {

    //For testing
    trace = false;/*from  ww  w  .  j a v  a2 s .com*/

    if (trace)
        tracei.beginTrace("initmeteva");
    batch = new SpriteBatch();
    atlas = new TextureAtlas(Gdx.files.internal("all.pack"));
    sbg = new SpaceBackground();
    sbg.initBackground();
    settings = new Settings();
    settings.load();
    highscoren = new Highscore();
    highscoren.load(false);
    highscoref = new Highscore();
    highscoref.load(true);
    mprof = new MarketProfile();
    mprof.load();
    mprof.reset();
    Gdx.app.setLogLevel(Application.LOG_ERROR);

    manager = new AssetManager();
    locale = Locale.getDefault();
    bundle = I18NBundle.createBundle(Gdx.files.internal("lang/bundle"), locale);
    Gdx.app.debug("Meteva", "using locale " + locale);

    for (int i = 0; i < 4; i++) {
        meteorExpl[i] = Gdx.audio.newSound(Gdx.files.internal("sounds/expl" + (i + 1) + ".ogg"));
    }
    playerExpl = Gdx.audio.newSound(Gdx.files.internal("sounds/raumschiffexpl.ogg"));
    laser = Gdx.audio.newSound(Gdx.files.internal("sounds/laser.ogg"));
    rush = Gdx.audio.newMusic(Gdx.files.internal("sounds/rush.mp3"));
    rush.setLooping(true);
    if (settings.musicEnabled())
        rush.play();

    Texture tex = new Texture(Gdx.files.internal("survivant.png"));
    tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    survivant = new BitmapFont(Gdx.files.internal("survivant.fnt"), new TextureRegion(tex), false);
    fontShader = new ShaderProgram(Gdx.files.internal("font.vert"), Gdx.files.internal("font.frag"));

    if (!fontShader.isCompiled()) {
        Gdx.app.error("fontShader", "compilation failed:\n" + fontShader.getLog());
    }

    Pixmap p = new Pixmap(1, 1, Format.RGBA8888);
    p.setColor(Color.WHITE);
    p.drawPixel(0, 0);
    whiteTexture = new Texture(p);
    p.dispose();

    //   camera = new OrthographicCamera(1920, 1080);
    //   camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    //   camera.setToOrtho(true);

    InputMultiplexer im = new InputMultiplexer();
    im.addProcessor(this);

    GestureDetector gd = new GestureDetector(this);
    im.addProcessor(gd);

    Gdx.input.setInputProcessor(im);

    width = Gdx.graphics.getWidth();
    height = Gdx.graphics.getHeight();

    musicb = new SoundButton(GScout.width * 0.022f, GScout.height * 0.02f, GScout.getRegion("ton"),
            GScout.getRegion("tonaus"), GScout.width * 0.065f);
    musicb.activated = !settings.musicEnabled();
    soundb = new SoundButton(GScout.width * 0.022f + 0.07f * GScout.width, GScout.height * 0.02f,
            GScout.getRegion("spielton"), GScout.getRegion("spieltonaus"), GScout.width * 0.065f);
    soundb.activated = !settings.soundsEnabled();

    state = new MainState();
    state.init();

    if (trace)
        tracei.endTrace();

}

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

License:Open Source License

protected Pixmap generatePixmap() {
    ArrayList<Float> shape = new ArrayList<Float>();
    float x0, y0, x1, y1, x2, y2, x3, y3;
    EAdList<Integer> pointsList = descriptor.getPoints();
    x0 = pointsList.get(0);/* ww  w  .j  av a2  s.  c  o  m*/
    y0 = pointsList.get(1);
    shape.add(x0);
    shape.add(y0);

    int pointIndex = 2;

    while (pointIndex < pointsList.size()) {
        int length = pointsList.get(pointIndex++);
        switch (length) {
        case 1:
            x1 = pointsList.get(pointIndex++);
            y1 = pointsList.get(pointIndex++);
            lineTo(x1, y1, shape);
            x0 = x1;
            y0 = y1;
            break;
        case 2:
            x1 = pointsList.get(pointIndex++);
            y1 = pointsList.get(pointIndex++);
            x2 = pointsList.get(pointIndex++);
            y2 = pointsList.get(pointIndex++);
            quadTo(x0, y0, x1, y1, x2, y2, shape);
            x0 = x2;
            y0 = y2;
            break;
        case 3:
            x1 = pointsList.get(pointIndex++);
            y1 = pointsList.get(pointIndex++);
            x2 = pointsList.get(pointIndex++);
            y2 = pointsList.get(pointIndex++);
            x3 = pointsList.get(pointIndex++);
            y3 = pointsList.get(pointIndex++);
            curveTo(x0, y0, x1, y1, x2, y2, x3, y3, shape);
            x0 = x3;
            y0 = y3;
            break;
        default:

        }
    }

    // TODO Probably this can be improved

    EAdPaint p = descriptor.getPaint();
    if (p == null) {
        p = ColorFill.WHITE;
    }

    float f[] = new float[shape.size()];
    for (int i = 0; i < shape.size(); i++) {
        f[i] = shape.get(i);
    }
    Polygon polygon = new Polygon(f);

    Rectangle rectangle = polygon.getBoundingRectangle();

    int borderWidth = p.getBorderWidth();
    int x = (int) rectangle.x;
    int y = (int) rectangle.y;
    int width = (int) (rectangle.x + rectangle.width);
    int height = (int) (rectangle.y + rectangle.height);

    Pixmap pixmap = new Pixmap(width + borderWidth * 2, height + borderWidth * 2, Pixmap.Format.RGBA8888);
    pixmapContains = new Pixmap(width + borderWidth * 2, height + borderWidth * 2, Pixmap.Format.RGBA8888);
    pixmapContains.setColor(0, 0, 0, 1);
    pixmap.setColor(0, 0, 0, 0);
    pixmap.fill();

    if (p.getFill() instanceof ColorFill) {
        ColorFill c = (ColorFill) p.getFill();
        pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f,
                c.getAlpha() / 255.0f);
    } else if (p.getFill() instanceof LinearGradientFill) {
        LinearGradientFill gradient = (LinearGradientFill) p.getFill();
        usingGradient = true;
        this.initGradientParams(gradient.getColor1(), gradient.getX0(), gradient.getY0(), gradient.getColor2(),
                gradient.getX1(), gradient.getY1());

    } else {
        pixmap.setColor(0, 0, 0, 1);
    }

    for (int i = x; i < width; i++) {
        for (int j = y; j < height; j++) {
            if (polygon.contains(i, j)) {
                if (usingGradient) {
                    this.setColor(pixmap, borderWidth + i, borderWidth + j);
                }
                pixmap.drawPixel(borderWidth + i, borderWidth + j);
                pixmapContains.drawPixel(borderWidth + i, borderWidth + j);
            }
        }
    }
    usingGradient = false;

    if (p.getBorder() != null) {
        if (p.getBorder() instanceof ColorFill) {
            ColorFill c = (ColorFill) p.getBorder();
            pixmap.setColor(c.getRed() / 255.0f, c.getGreen() / 255.0f, c.getBlue() / 255.0f,
                    c.getAlpha() / 255.0f);
        } else if (p.getBorder() instanceof LinearGradientFill) {
            LinearGradientFill gradient = (LinearGradientFill) p.getBorder();
            usingGradient = true;
            initGradientParams(gradient.getColor1(), gradient.getX0(), gradient.getY0(), gradient.getColor2(),
                    gradient.getX1(), gradient.getY1());
        }

        float previousX = 0;
        float previousY = 0;
        float currentX;
        float currentY;
        for (int k = 0; k < shape.size(); k += 2) {
            currentX = shape.get(k);
            currentY = shape.get(k + 1);
            if (k >= 2) {
                for (int i = 1; i <= borderWidth; i++) {
                    if (usingGradient) {
                        this.setColor(pixmap, (int) previousX + i, (int) previousY + i);
                    }
                    pixmap.drawLine((int) previousX + i, (int) previousY + i, (int) currentX + i,
                            (int) currentY + i);
                    pixmapContains.drawLine((int) previousX + i, (int) previousY + i, (int) currentX + i,
                            (int) currentY + i);
                }
            }
            previousX = currentX;
            previousY = currentY;
        }
        for (int i = 1; i <= borderWidth; i++) {
            pixmap.drawLine((int) previousX + i, (int) previousY + i, (int) shape.get(0).intValue() + i,
                    (int) shape.get(1).intValue() + i);
            pixmapContains.drawLine((int) previousX + i, (int) previousY + i, (int) shape.get(0).intValue() + i,
                    (int) shape.get(1).intValue() + i);
        }

    }
    usingGradient = false;
    return pixmap;
}

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 ww  .  j a va2s . c  o 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.assets.drawables.shapes.GdxRectangleShape.java

License:Open Source License

@Override
protected Pixmap generatePixmap() {

    EAdPaint paint = descriptor.getPaint();
    EAdFill border = paint.getBorder();//from w w w .  j a v  a2 s  . co m
    EAdFill fill = paint.getFill();
    int borderWidth = paint.getBorderWidth();

    int pwidth = descriptor.getWidth() + borderWidth * 2;
    int pheight = descriptor.getHeight() + borderWidth * 2;

    Pixmap pixmap = new Pixmap(pwidth, pheight, Pixmap.Format.RGBA8888);
    pixmapContains = new Pixmap(pwidth, pheight, Pixmap.Format.RGBA8888);
    pixmapContains.setColor(0, 0, 0, 1);
    pixmapContains.fillRectangle(0, 0, pwidth, pheight);

    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.drawRectangle(0, 0, pwidth, pheight);
    }

    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.fillRectangle(borderWidth, borderWidth, descriptor.getWidth(), descriptor.getHeight());
    } else if (fill instanceof LinearGradientFill) {
        LinearGradientFill l = (LinearGradientFill) fill;
        initGradientParams(l.getColor1(), l.getX0(), l.getY0(), l.getColor2(), l.getX1(), l.getY1());
        for (int i = borderWidth; i < descriptor.getWidth() + borderWidth; i++) {
            for (int j = borderWidth; j < descriptor.getHeight() + borderWidth; j++) {
                setColor(pixmap, i, j);
                pixmap.drawPixel(i, j);
            }
        }
    }

    return pixmap;
}