use of java.awt.Graphics2D in project openblocks by mikaelhg.
the class RBHighlightHandler method paintComponent.
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(new Color(0, 0, 0, 0));
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, HIGHLIGHT_ALPHA));
if (hImage != null) {
g2.drawImage(hImage, 0, 0, null);
}
}
use of java.awt.Graphics2D in project d54 by mitrisdev.
the class MITrisPlugin method loop.
@Override
protected void loop() {
Display2D display = getDisplay();
Graphics2D g = display.getGraphics();
switch(gameState) {
case IDLE:
animTime = 0;
animTimeLastStep = 0;
logoPos = 0;
gameState = State.IDLE_ANIM;
break;
case IDLE_ANIM:
animTime += timestep;
if (animTime - animTimeLastStep >= LOGO_ANIM_STEP) {
animTimeLastStep = animTime;
logoPos++;
if (logoPos > 100)
gameState = State.IDLE;
}
g.drawImage(mitrisLogo, 10 - logoPos, 6, null);
break;
case GAME_START:
mitrisGame = new MITrisGame(width, height, timestep);
gameState = State.GAME;
break;
case GAME:
if (!controller.isConnected())
return;
//move piece down if it's time
mitrisGame.clockTick();
gameDisplayTime = mitrisGame.getTime();
sendBoardToDisplay(mitrisGame.getDisplayBoard(), display);
if (mitrisGame.isGameOver()) {
System.out.println(String.format("Game over! Lines cleared: %d Time: %3.1f", mitrisGame.getDisplayBoard().getNumCleared(), mitrisGame.getTime()));
gameState = State.GAME_END_1;
gameOverBoard = mitrisGame.getDisplayBoard();
animTime = 0;
String extra = "";
if (gameOverBoard.getLevel() >= 5)
extra = " Great job!";
if (gameOverBoard.getLevel() >= 8)
extra = " Amazing!!";
TwitterClient.tweet(String.format("Someone just played Tetris on the MIT Green Building! " + "They cleared %d lines and lasted %1.1f seconds!%s #mittetris", gameOverBoard.getNumCleared(), mitrisGame.getTime(), extra));
}
break;
case GAME_END_1:
animTime += timestep;
if (animTime > GAME_END_WAIT) {
gameState = State.GAME_END_2;
animTime = 0;
animTimeLastStep = 0;
if (gameOverBoard.getLevel() >= 8) {
gameState = State.GAME_END_ALT_2;
circTime = new double[] { -100, -100, -100, -100, -100 };
circX = new double[5];
circY = new double[5];
circHue = new double[5];
circPos = 0;
}
}
sendBoardToDisplay(gameOverBoard, display);
break;
case GAME_END_2:
animTime += timestep;
if (animTime - animTimeLastStep >= ANIM_TIME_STEP) {
animTimeLastStep = animTime;
if (gameOverBoard.isBoardEmpty()) {
gameState = State.IDLE;
}
gameOverBoard = gameOverBoard.shiftBoardDown();
}
sendBoardToDisplay(gameOverBoard, display);
break;
case GAME_END_ALT_2:
animTime += timestep;
if (animTime >= CIRC_ANIM_FADE_WAIT_TIME) {
if (animTime <= CIRC_ANIM_FADE_WAIT_TIME + CIRC_ANIM_FADE_TIME) {
double brightness = 1 - (animTime - CIRC_ANIM_FADE_WAIT_TIME) / CIRC_ANIM_FADE_TIME;
sendBoardToDisplay(gameOverBoard, display, brightness);
}
} else
sendBoardToDisplay(gameOverBoard, display);
if (animTime - animTimeLastStep >= CIRC_ADD_TIME && animTime <= CIRC_ANIM_STOPADD_TIME) {
animTimeLastStep = animTime;
circX[circPos] = Math.random() * width;
circY[circPos] = Math.random() * height;
circTime[circPos] = animTime - 0.3;
circHue[circPos] = Math.random();
circPos = (circPos + 1) % circX.length;
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
for (int k = 0; k < circX.length; k++) {
g.setColor(new Color(Color.HSBtoRGB((float) circHue[k], 1, 1)));
g.setStroke(new BasicStroke(1.5f));
double circH = (animTime - circTime[k]) * 5;
double circW = circH / display.getPixelAspect();
g.draw(new Ellipse2D.Double(circX[k] - circW / 2, circY[k] - circH / 2, circW, circH));
}
if (animTime >= CIRC_ANIM_TOTAL_TIME)
gameState = State.IDLE;
}
}
use of java.awt.Graphics2D in project d54 by mitrisdev.
the class VUMeterPlugin method loop.
@Override
protected void loop() {
audio.frameUpdate();
//render
Graphics2D g = getDisplay().getGraphics();
int w = getDisplay().getWidth();
int h = getDisplay().getHeight();
for (int i = 0; i < w; i++) {
double level = Math.log10(amplitudeMaxRatio * audio.getFFTMagBins()[i] / audio.getFFTMaxValue()) / Math.log10(amplitudeMaxRatio);
double levelOld = Math.log10(amplitudeMaxRatio * fftBinsOld[i] / audio.getFFTMaxValue()) / Math.log10(amplitudeMaxRatio);
// double level=fftBins[i]/max*1.5f;
for (int j = 0; j < h; j++) {
if (j >= (int) Math.round(h - level * h))
getDisplay().setPixelRGB(i, j, getColor(i, j, 1));
}
/* if (level>levelOld)
{
g.setColor(Color.red);
g.drawLine(i,(int)(h-levelOld*h),i,(int)(h-level*h));
g.setColor(Color.green);
g.drawLine(i, h, i, (int)(h-levelOld*h));
}
else
{
g.setColor(Color.green);
// g.setColor(Color.getHSBColor((float) Math.min(0.4f, 0.4f-(level-levelOld)), 1, 1));
g.drawLine(i, h, i, (int)(h-level*h));
}*/
}
fftBinsOld = audio.getFFTMagBins();
}
use of java.awt.Graphics2D in project jersey by jersey.
the class SparklinesResource method smooth.
@Path("smooth")
@GET
public Response smooth(@DefaultValue("2") @QueryParam("step") final int step, @DefaultValue("true") @QueryParam("min-m") final boolean hasMin, @DefaultValue("true") @QueryParam("max-m") final boolean hasMax, @DefaultValue("true") @QueryParam("last-m") final boolean hasLast, @DefaultValue("blue") @QueryParam("min-color") final ColorParam minColor, @DefaultValue("green") @QueryParam("max-color") final ColorParam maxColor, @DefaultValue("red") @QueryParam("last-color") final ColorParam lastColor) {
final BufferedImage image = new BufferedImage(data.size() * step - 4, imageHeight, BufferedImage.TYPE_INT_RGB);
final Graphics2D g = image.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, image.getWidth(), image.getHeight());
g.setColor(Color.gray);
final int[] xs = new int[data.size()];
final int[] ys = new int[data.size()];
final int gap = 4;
final float d = (limits.width() + 1) / (float) (imageHeight - gap);
for (int i = 0, x = 0; i < data.size(); i++, x += step) {
final int v = data.get(i);
xs[i] = x;
ys[i] = imageHeight - 3 - (int) ((v - limits.lower()) / d);
}
g.drawPolyline(xs, ys, data.size());
if (hasMin) {
final int i = data.indexOf(Collections.min(data));
g.setColor(minColor);
g.fillRect(xs[i] - step / 2, ys[i] - step / 2, step, step);
}
if (hasMax) {
final int i = data.indexOf(Collections.max(data));
g.setColor(maxColor);
g.fillRect(xs[i] - step / 2, ys[i] - step / 2, step, step);
}
if (hasMax) {
g.setColor(lastColor);
g.fillRect(xs[xs.length - 1] - step / 2, ys[ys.length - 1] - step / 2, step, step);
}
return Response.ok(image).tag(tag).build();
}
use of java.awt.Graphics2D in project Openfire by igniterealtime.
the class GraphServlet method writePDFContent.
private void writePDFContent(HttpServletRequest request, HttpServletResponse response, JFreeChart[] charts, Statistic[] stats, long starttime, long endtime, int width, int height) throws IOException {
try {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
writer.setPageEvent(new PDFEventListener(request));
document.open();
int index = 0;
int chapIndex = 0;
for (Statistic stat : stats) {
String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
String dateName = JiveGlobals.formatDate(new Date(starttime)) + " - " + JiveGlobals.formatDate(new Date(endtime));
Paragraph paragraph = new Paragraph(serverName, FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
document.add(paragraph);
paragraph = new Paragraph(dateName, FontFactory.getFont(FontFactory.HELVETICA, 14, Font.PLAIN));
document.add(paragraph);
document.add(Chunk.NEWLINE);
document.add(Chunk.NEWLINE);
Paragraph chapterTitle = new Paragraph(++chapIndex + ". " + stat.getName(), FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD));
document.add(chapterTitle);
// total hack: no idea what tags people are going to use in the description
// possibly recommend that we only use a <p> tag?
String[] paragraphs = stat.getDescription().split("<p>");
for (String s : paragraphs) {
Paragraph p = new Paragraph(s);
document.add(p);
}
document.add(Chunk.NEWLINE);
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template = contentByte.createTemplate(width, height);
Graphics2D graphs2D = template.createGraphics(width, height, new DefaultFontMapper());
Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height);
charts[index++].draw(graphs2D, rectangle2D);
graphs2D.dispose();
float x = (document.getPageSize().width() / 2) - (width / 2);
contentByte.addTemplate(template, x, writer.getVerticalPosition(true) - height);
document.newPage();
}
document.close();
// setting some response headers
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
// setting the content type
response.setContentType("application/pdf");
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
} catch (DocumentException e) {
Log.error("error creating PDF document: " + e.getMessage());
}
}
Aggregations