List of usage examples for com.badlogic.gdx.graphics Pixmap drawLine
public void drawLine(int x, int y, int x2, int y2)
From source file:com.alma42.mapgen.game.WorldController.java
License:Apache License
private Pixmap createUser(final int width, final int height) { final Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888); // Fill square with red color at 50% opacity pixmap.setColor(1, 0, 0, 0.5f);//from w ww . ja va 2s . co m pixmap.fill(); // Draw a yellow-colored X shape on square pixmap.setColor(1, 1, 0, 1); pixmap.drawLine(0, 0, width, height); pixmap.drawLine(width, 0, 0, height); // Draw a cyan-colored border around square pixmap.setColor(0, 1, 1, 1); pixmap.drawRectangle(0, 0, width, height); return pixmap; }
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);/* w w w. j a v a2 s . com*/ 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.ridiculousRPG.video.cortado.CortadoPlayerAppletWrapper.java
License:Open Source License
/** * Instantiates a new video player. Don't forget to dispose the player! * //from ww w .j a v a2 s .co m * @param url * url to ogg / ogv file * @param screenBounds * the screen position, width and height * @param projectToMap * Defines whether to project the video onto the map or onto the * screen coordinates * @param withAudio * if false, the audio channel will be disabled. */ public CortadoPlayerAppletWrapper(URL url, Rectangle screenBounds, boolean projectToMap, boolean withAudio, boolean drawPlaceholder) { this.screenBounds = new Rectangle(screenBounds); this.projectToMap = projectToMap; if (!projectToMap) { GameBase gb = GameBase.$(); this.screenBounds.width /= gb.getScreen().width; this.screenBounds.height /= gb.getScreen().height; this.screenBounds.x /= gb.getScreen().width; this.screenBounds.y /= gb.getScreen().height; } int width = (int) screenBounds.width; int height = (int) screenBounds.height; textureRef = TextureRegionLoader.obtainEmptyRegion(width, height, Format.RGBA8888); if (drawPlaceholder) { Pixmap placeholder = new Pixmap(width, height, Format.RGBA8888); placeholder.setColor(0, 0, 0, 1); placeholder.fillRectangle(0, 0, width, height); placeholder.setColor(.7f, .7f, .7f, 1); placeholder.fillCircle(width / 2, height / 2, Math.min(width, height) / 3); placeholder.setColor(.4f, .4f, .4f, 1); placeholder.drawRectangle(0, 0, width, height); placeholder.drawRectangle(2, 2, width - 4, height - 4); placeholder.drawLine(1, 0, width, height - 1); placeholder.drawLine(0, 1, width - 1, height); placeholder.drawLine(1, height, width, 1); placeholder.drawLine(0, height - 1, width - 1, 0); textureRef.draw(placeholder); placeholder.dispose(); } graphicsPixmap = new VideoARGBintPixmapWrapper(); player = new CortadoPlayerApplet(graphicsPixmap); initPlayer(); player.setParam("url", url.toString()); player.setParam("audio", String.valueOf(withAudio)); player.setSize(width, height); player.setStub(this); player.init(); player.start(); }
From source file:es.eucm.ead.editor.view.widgets.draw.SlideColorPicker.java
License:Open Source License
private void drawColor(Pixmap pixmap, int x, float r, float g, float b, float a) { pixmap.setColor(r, g, b, a);/* ww w.java2s . c o m*/ pixmap.drawLine(x, 0, x, pixmap.getHeight()); }
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);//from ww w. j a v a 2 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.components.renderers.shape.ShapeToPixmap.java
License:Open Source License
/** Creates a polygon **/ private Pixmap createPolygon(Polygon schemaPolygon) { if (schemaPolygon.getPoints().size < 6) { Gdx.app.error("ShapeFactory", "Invalid polygon. It contains less than 3 points."); return null; }//from w w w.j a va 2s. c o m float[] points = new float[schemaPolygon.getPoints().size]; for (int i = 0; i < schemaPolygon.getPoints().size; i++) { points[i] = schemaPolygon.getPoints().get(i); // See comment in setGradientColor to understand this if (i % 2 != 0) { points[i] = pixmapHeight - points[i]; } } com.badlogic.gdx.math.Polygon polygon = new com.badlogic.gdx.math.Polygon(points); com.badlogic.gdx.math.Rectangle rectangle = polygon.getBoundingRectangle(); Pixmap pixmap = new Pixmap((int) rectangle.getWidth(), (int) rectangle.getHeight(), Format.RGBA8888); // Fill pixmap.setColor(color1); for (int i = 0; i < rectangle.getWidth(); i++) { for (int j = 0; j < rectangle.getHeight(); j++) { if (polygon.contains(i, j)) { if (useGradient) { setGradientColor(pixmap, i, j); } pixmap.drawPixel(i, j); } } } // Border if (hasBorder) { pixmap.setColor(borderColor); int prevX = (int) points[0]; int prevY = (int) points[1]; for (int i = 2; i < points.length; i += 2) { int x = (int) points[i]; int y = (int) points[i + 1]; pixmap.drawLine(prevX, prevY, x, y); prevX = x; prevY = y; } } return pixmap; }
From source file:es.eucm.ead.engine.renderers.ShapesFactory.java
License:Open Source License
/** Creates a polygon **/ private Pixmap createPolygon(Polygon schemaPolygon) { if (schemaPolygon.getPoints().size() < 6) { Gdx.app.error("ShapeFactory", "Invalid polygon. It contains less than 3 points."); return null; }// w w w .j a v a2 s. c om float[] points = new float[schemaPolygon.getPoints().size()]; for (int i = 0; i < schemaPolygon.getPoints().size(); i++) { points[i] = schemaPolygon.getPoints().get(i); // See comment in setGradientColor to understand this if (i % 2 != 0) { points[i] = pixmapHeight - points[i]; } } com.badlogic.gdx.math.Polygon polygon = new com.badlogic.gdx.math.Polygon(points); com.badlogic.gdx.math.Rectangle rectangle = polygon.getBoundingRectangle(); Pixmap pixmap = new Pixmap((int) rectangle.getWidth(), (int) rectangle.getHeight(), Format.RGBA8888); // Fill pixmap.setColor(color1); for (int i = 0; i < rectangle.getWidth(); i++) { for (int j = 0; j < rectangle.getHeight(); j++) { if (polygon.contains(i, j)) { if (useGradient) { setGradientColor(pixmap, i, j); } pixmap.drawPixel(i, j); } } } // Border if (hasBorder) { pixmap.setColor(borderColor); int prevX = (int) points[0]; int prevY = (int) points[1]; for (int i = 2; i < points.length; i += 2) { int x = (int) points[i]; int y = (int) points[i + 1]; pixmap.drawLine(prevX, prevY, x, y); prevX = x; prevY = y; } } return pixmap; }
From source file:name.herve.bastod.gui.screen.game.OverlayManager.java
License:Open Source License
private void drawTintedSquare(Pixmap p, Color c, Vector v) { Dimension dimB = engine.getBoardDimension(); int sqs = engine.getGridSquareSize(); int step = (sqs - 2) / 7; int h = dimB.getH(); int x = v.getXInt(); int y = v.getYInt(); p.setColor(c);/*from w w w .ja v a 2 s . c om*/ for (int dx = step; dx < sqs; dx += step) { p.drawLine(x + dx, h - y, x + dx, h - y - sqs + 1); } for (int dy = step; dy < sqs; dy += step) { p.drawLine(x + 1, h - y - dy, x + sqs - 1, h - y - dy); } }
From source file:name.herve.bastod.gui.screen.game.OverlayManager.java
License:Open Source License
public void renderGrid() { if (grid == null) { Dimension dimG = engine.getGridDimension(); Dimension dimB = engine.getBoardDimension(); int sqs = engine.getGridSquareSize(); Blending bck = Pixmap.getBlending(); Pixmap.setBlending(Blending.None); Pixmap p = new Pixmap(dimB.getW() + 1, dimB.getH() + 1, Pixmap.Format.RGBA8888); Color c = Color.WHITE.cpy(); c.a = 0.2f;/*from w ww .j a v a 2s.c o m*/ p.setColor(c); for (int x = 0; x <= dimG.getW(); x++) { int bx = x * sqs; p.drawLine(bx, 0, bx, dimB.getH() - 1); } for (int y = 0; y <= dimG.getH(); y++) { int by = y * sqs; p.drawLine(0, by, dimB.getW() - 1, by); } grid = new Texture(p); p.dispose(); Pixmap.setBlending(bck); } batchBegin(); draw(grid, Engine._SP_SIDE, Engine._SP_BOTTOM); batchEnd(); }
From source file:name.herve.bastod.gui.screen.game.SpriteManager.java
License:Open Source License
private void renderPath(Mobile m) { if (!pathTextures.containsKey(m)) { Dimension dimB = engine.getBoardDimension(); Blending bck = Pixmap.getBlending(); Pixmap.setBlending(Blending.None); Pixmap p = new Pixmap(dimB.getW() + 1, dimB.getH() + 1, Pixmap.Format.RGBA8888); Color c = Color.GREEN.cpy(); p.setColor(c);/* w ww .j av a 2 s. c o m*/ Vector current = m.getPlayer().getStartPositionOnBoard(); for (Vector next : m.getUnsmoothedPath()) { p.drawLine(current.getXInt(), dimB.getH() - current.getYInt(), next.getXInt(), dimB.getH() - next.getYInt()); current = next; } c = Color.YELLOW.cpy(); p.setColor(c); current = m.getPlayer().getStartPositionOnBoard(); for (Vector next : m.getPath()) { p.drawLine(current.getXInt(), dimB.getH() - current.getYInt(), next.getXInt(), dimB.getH() - next.getYInt()); current = next; } pathTextures.put(m, new Texture(p)); p.dispose(); Pixmap.setBlending(bck); } draw(pathTextures.get(m), Engine._SP_SIDE, Engine._SP_BOTTOM); // tPath.dispose(); }