/** * Примечание: по умолчанию метод возвращает белый цвет. * * @param color Цвет из нашего кастомного enum * @return Color, с которым работает LWJGL */ private Color convertColor(TpReadableColor color) { switch (color){ case RED: return new Color(ReadableColor.RED); case GREEN: return new Color(ReadableColor.GREEN); case BLUE: return new Color(ReadableColor.BLUE); case AQUA: return new Color(ReadableColor.CYAN); case YELLOW: return new Color(ReadableColor.YELLOW); case ORANGE: return new Color(ReadableColor.ORANGE); case PURPLE: return new Color(ReadableColor.PURPLE); case BLACK: return new Color(ReadableColor.BLACK); default: return new Color(ReadableColor.WHITE); } }
public void setVerticalGradient(ReadableColor col1, ReadableColor col2) { ReadableColor[] cols = new ReadableColor[9]; cols[0] = col1; cols[1] = col1; cols[2] = col1; cols[6] = col2; cols[7] = col2; cols[8] = col2; Color inter = ColorInterpolator.interpolate(col1, col2, .5f); cols[3] = inter; cols[4] = inter; cols[5] = inter; setColors(cols); }
public void setCentralGradient(ReadableColor col1, ReadableColor col2) { ReadableColor[] cols = new ReadableColor[9]; cols[4] = col1; cols[0] = col2; cols[2] = col2; cols[6] = col2; cols[8] = col2; // ~1/sqrt(2), the factor to adjust the colors by to produce a circular pattern. Color temp = ColorInterpolator.interpolate(col1, col2, .707107f); cols[1] = temp; cols[3] = temp; cols[5] = temp; cols[7] = temp; setColors(cols); }
public void setHorizontalGradient(ReadableColor col1, ReadableColor col2) { ReadableColor[] cols = new ReadableColor[9]; cols[0] = col1; cols[3] = col1; cols[6] = col1; cols[1] = col2; cols[4] = col2; cols[7] = col2; Color inter = ColorInterpolator.interpolate(col1, col2, .5f); cols[2] = inter; cols[5] = inter; cols[8] = inter; setColors(cols); }
/** * Interpolates between the given {@link Color}s according to the given * amount. The amount should be between 0 and 1, all other numbers are produce * undefined results. * * @param col1 The first {@link Color} in the interpolation. * @param col2 The second {@link Color} in the interpolation. * @param amt The amount to interpolate. * @param out The {@link Color} to store the output in. * @return The interpolated {@link Color}. */ public static Color interpolate(ReadableColor col1, ReadableColor col2, float amt, Color out) { int num = (int) (col1.getAlpha() * (1 - amt) + col2.getAlpha() * amt); out.setAlpha(num); num = (int) (col1.getRed()* (1 - amt) + col2.getRed() * amt); out.setRed(num); num = (int) (col1.getGreen()* (1 - amt) + col2.getGreen() * amt); out.setGreen(num); num = (int) (col1.getBlue()* (1 - amt) + col2.getBlue() * amt); out.setBlue(num); return out; }
private static int createRobotDisplayList(Color colour) { int listID = glGenLists(1); glNewList(listID, GL_COMPILE); double radius = SimulationSettings.robotRadius; glBegin(GL_TRIANGLE_FAN); glColor4d((double)colour.getRed() / 255d, (double)colour.getGreen() / 255d, (double)colour.getBlue() / 255d, 1); glVertex2d(0, 0); for(int angle = 0; angle <= 360; angle++) { double x = Math.sin(Math.toRadians(-angle)) * radius; double y = Math.cos(Math.toRadians(-angle)) * radius; glVertex2d(x, y); } glEnd(); glBegin(GL_LINES); glColor4d(0, 0, 0, 1); glVertex2d(0, 0.1*radius); glVertex2d(0, 0.9*radius); glEnd(); glEndList(); return listID; }
protected void paintGrid(GC gc) { if (!GridVisible) return; gc.setColor(Color.GREY); int ts = tileset.getTileSize(); int maxX = image.getWidth() / ts; int maxY = image.getHeight() / ts; for (int x = 1; x < maxX; x++) { gc.drawLine(x * ts, 0, x * ts, image.getHeight()); } for (int y = 1; y < maxY; y++) { gc.drawLine(0, y * ts, image.getWidth(), y * ts); } }
private void paintRaster(GC gc) { Rectangle drawRect = gc.getClip(); gc.setColor(Color.GREY); gc.setAlpha(127); int ts = tileset.getTileSize(); int maxX = Math.min((drawRect.x + drawRect.width / ts), map.width - 1); int maxY = Math.min((drawRect.y + drawRect.height / ts), map.height - 1); for(int x = drawRect.x / ts; x <= maxX; x++) { for(int y = drawRect.y / ts; y <= maxY; y++) { gc.drawRectangle(x * ts, y * ts, ts - 1, ts - 1); } } gc.setAlpha(255); }
private static PaintListener getPaintListener() { return new PaintListener() { @Override public void paint(GC gc) { System.out.println("Paint"); // gc.setColor(Color.BLACK); // gc.drawImage(image, 15, 15); gc.drawImage(image, 0, 0, 2048, 1024, 0, 0, 2048, 1024); Rectangle bounds = panel.getBounds(); gc.setColor(Color.RED); gc.drawLine(100, 100, bounds.width - 100, bounds.height - 100); gc.drawLine(bounds.width - 100, 100, 100, bounds.height - 100); // drawTorus(1, 1.9f + ((float) Math.sin((0.004f * 0))), 15, 15); } }; }
public DebugSprite(GameMap map, short bits) { super(Images.createImage(map.getTileSize(), map.getTileSize())); int ts = map.getTileSize(); this.width = ts; this.height = ts; this.color = new Color(0, 0, 0, 176); this.fill = true; getImage().setColor(color); int maskSize = ts / 4; for(int i = 0; i < 16; i++) { if ((bits & (1 << i)) != 0) getImage().drawRect( (i % 4) * maskSize, (i / 4) * maskSize, maskSize, maskSize, fill); } }
@EventMethod public Result fadeOut(int duration, int flags) { this.flags = FADE_OUT | flags; if ((flags & FADE_SCREEN) != 0) { sprite.setColor(Color.WHITE, 0); createScreenShot(0); this.flags |= WAIT; duration = 1; } else { sprite.setColor(Color.BLACK, duration); } System.out.println("Start fade out. Frames: + " + duration); return getInterpreterResult(duration, this.flags); }
/** * Отрисовывает отдельную ячейку * * @param x Координата отрисовки X * @param y Координата отрисовки Y * @param color Цвет ячейки */ private void drawCell(int x, int y, Color color) { glColor3ub(color.getRedByte(), color.getGreenByte(), color.getBlueByte()); glBegin(GL_QUADS); glTexCoord2f(0,0); glVertex2f(x,y+ Constants.CELL_SIZE); glTexCoord2f(1,0); glVertex2f(x+ Constants.CELL_SIZE,y+ Constants.CELL_SIZE); glTexCoord2f(1,1); glVertex2f(x+ Constants.CELL_SIZE, y); glTexCoord2f(0,1); glVertex2f(x, y); glEnd(); }
public Color getColor(double d, double e, double f, int phase1, int phase2, int phase3, float g) { int center = 128; int width = 127; int red = (int) ((Math.sin((d * g) + phase1) * width) + center); int grn = (int) ((Math.sin((e * g) + phase2) * width) + center); int blu = (int) ((Math.sin((f * g) + phase3) * width) + center); return new Color(red, grn, blu); }
public Color getColor(double d, double e, double f, int phase1, int phase2, int phase3, float i) { int center = 128; int width = 127; int red = (int) ((Math.sin((d * i) + phase1) * width) + center); int grn = (int) ((Math.sin((e * i) + phase2) * width) + center); int blu = (int) ((Math.sin((f * i) + phase3) * width) + center); return new Color(red, grn, blu); }
private void flushIfNeeded(IAnimationImage image, Color color) { if (currentImage != image || !currentColor.equals(color) || currentSpriteInBatch == BATCH_SIZE) { flush(); } currentColor.setColor(color); currentImage = image; }
public static void drawRectangle(Color color, int x, int y, int width, int height, int zLevel) { float colorMod = 1F / 255F; GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(colorMod * color.getRed(), colorMod * color.getGreen(), colorMod * color.getBlue(), colorMod * color.getAlpha()); drawRectangle(x, y, 0, 0, width, height, zLevel); GL11.glDisable(GL11.GL_BLEND); GL11.glColor4f(1F, 1F, 1F, 1F); GL11.glEnable(GL11.GL_TEXTURE_2D); }
private void processColors(DataNode data) { Color[] cols = new Color[9]; List<Integer> colors = (List<Integer>) data.data; for(int i = 0; i < 9; i++) cols[i] = processColorData(colors.get(i)); setColors(cols); }
private void processGradient(DataNode data, GradientType type) { List<Integer> cols = (List<Integer>) data.data; Color color1 = processColorData(cols.get(0)); Color color2 = processColorData(cols.get(1)); setGradient(color1, color2, type); }
private void paintAutotiles(GC gc) { Image image = imageList.get(index); TilemapUtil.paintGrid(gc, 0, 0, image.getWidth(), image.getHeight(), tileset.getTileSize() / 2); gc.setColor(Color.WHITE); gc.drawImage(image, 0, 0); paintCursor(gc); }
private void paintTiles(GC gc, boolean useTempLayer) { // int ts = tileset.getTileSize(); int minX = 0;// Math.max(e.x, 0) / ts; int minY = 0;// Math.max(e.y, 0) / ts; int maxX = map.width;// Math.min((e.x + e.width) / ts + 1, map.width); int maxY = map.height;// Math.min((e.y + e.height) / ts + 1, // map.height); // System.out.println("Paint Tiles in: " + minX + ", " + minY + ", " + // maxX + ", " + maxY); Rectangle bounds = editor.getViewBounds(); for(int z = 0; z < Map.LAYERS; z++) { if (currentLayer == z && dimLayers) { gc.setColor(Color.BLACK); gc.setAlpha(127); gc.fillRectangle(0, 0, bounds.width, bounds.height); gc.setColor(Color.WHITE); } else if(z > currentLayer && fadeLayers) { gc.setAlpha(127); } for(int x = minX; x < maxX; x++) for(int y = minY; y < maxY; y++) { if(z == this.currentLayer && tempLayer != null && tempLayer.contains(x, y)) { paintTempLayer(gc, x, y); } else { paintTile(gc, map.data[x][y][z], x, y); } } } gc.setAlpha(255); }
private RenderJob(Image owner) { this.owner = owner; this.color = new Color(owner.getColor()); // this.font = owner.getFont(); this.blendMode = owner.getBlendMode(); }
public static void setColor(ReadableColor color, int alpha) { Color c = new Color(color); c.setAlpha(alpha); setColor(c); }
private void mixColor(Color dst, ReadableColor s1, ReadableColor s2, float value) { dst.set( (int) (s1.getRed() * (1-value) + s2.getRed() * value), (int) (s1.getGreen() * (1-value) + s2.getGreen() * value), (int) (s1.getBlue() * (1-value) + s2.getBlue() * value), (int) (s1.getAlpha() * (1-value) + s2.getAlpha() * value)); }
public void init(ParticleType type, ParticlePhysik physik, Vector pos) { this.type = type; this.physik = physik; this.lifeTime = 0; this.pos = new Vector(pos); if (this.speed == null) this.speed = new Vector(); if (this.color == null) this.color = new Color(); }
private void createCollisionAreaSprite(int index) { Rectangle rect = map.getCollisionSystem().getArea(index); Sprite sprite = new DebugSprite(rect.width, rect.height, new Color(255, 0, 0), false); sprite.setOX(-rect.x); sprite.setOY(-rect.y); sprite.setDepth(900); CSAreaSprites[index] = sprite; }
private static Image getCollisionImage() { if (cMaskImage == null) { cMaskImage = Images.createImage(tileSize, tileSize); cMaskImage.setColor(new Color(0, 0, 0, 176)); cMaskImage.drawRect(0, 0, cMaskImage.getWidth(), cMaskImage.getHeight(), true); } return cMaskImage; }
public DebugSprite(int width, int height, Color color, boolean fill) { super(Images.createImage(width, height)); this.width = width; this.height = height; this.color = color; this.fill = fill; getImage().setColor(color); getImage().drawRect(0, 0, width, height, fill); }
@Override public void postUpdate() { Image img = sprite.getImage(); img.clear(Image.COLOR_TRANSPARENT); // CuinaObject obj = Game.getWorld().getObject(1_000_001); CuinaWorld world = Game.getWorld(); for(Integer id : world.getObjectIDs()) { CuinaObject obj = world.getObject(id); Model model = (Model) obj.getExtension(Model.EXTENSION_KEY); if (model == null) continue; Sprite s = model.getSprite(); img.setBlendMode(Image.COMPOSITE_NORMAL); img.setColor(Color.WHITE); img.drawImage( (int) (s.getX() - model.getOX()), (int) (s.getY() - model.getOY() + model.getHeight() * 2), s.getImage(), Image.V_FLIP); } img.drawImage(0, 0, groundMask); img.setBlendMode(Image.COMPOSITE_ADD); }
public void setColor(ReadableColor color, int duration) { this.dstColor = color; this.duration = duration; if (duration <= 0) getImage().setColor(color); else { Color c = getImage().getColor(); red = c.getRed(); green = c.getGreen(); blue = c.getBlue(); alpha = c.getAlpha(); } }
private LoadingCircle(final @Nonnull Color loading, final @Nonnull Color progress, final @Nonnull Color design) { this.loading = loading; this.progress = progress; this.design = design; }
public RGBA(Color cl) { this(cl.getRed(), cl.getGreen(), cl.getBlue(), cl.getAlpha()); }
public RGBA(java.awt.Color cl) { this(cl.getRed(), cl.getGreen(), cl.getBlue(), cl.getAlpha()); }
public java.awt.Color toAWTColor() { return new java.awt.Color(Red, Green, Blue, Alpha); }
public Color toColor() { return new Color(Red, Green, Blue, Alpha); }
/** * set gl color from a LWJGL Color object */ public static void glColor(final Color color) { GL11.glColor4d(color.getRed() / 255., color.getGreen() / 255., color.getBlue() / 255., color.getAlpha() / 255.); }
/** * set gl color from an AWT Color object */ public static void glColor(final java.awt.Color color) { GL11.glColor4d(color.getRed() / 255., color.getGreen() / 255., color.getBlue() / 255., color.getAlpha() / 255.); }
/** * set gl clear color from a LWJGL Color object */ public static void glClear(final Color color, int bufferId) { GL11.glClearColor(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); GL11.glClear(bufferId); }
/** * set gl clear color from an AWT Color object */ public static void glClear(final java.awt.Color color, int bufferId) { GL11.glClearColor(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); GL11.glClear(bufferId); }
public static org.lwjgl.util.Color glRandomColor() { return new org.lwjgl.util.Color(randomSeed.nextInt(256), randomSeed.nextInt(256), randomSeed.nextInt(256)); }