LEDControl/src/main/java/de/zuim/ledcontrol/effects/ClockEffect.java
2021-03-14 12:18:00 +01:00

49 lines
1.5 KiB
Java

package de.zuim.ledcontrol.effects;
import de.zuim.ledcontrol.LEDEffect;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import static de.zuim.ledcontrol.LEDControl.HEIGHT;
public class ClockEffect implements LEDEffect {
private Font font = new Font("crosextra-carlito", Font.BOLD, 10 * getScale());
private double posOffset = 3;
@Override
public String getDescription() {
return "LED Clock";
}
int iteration = 0;
public void fontSwitcher() {
if (++iteration % 100 == 0) {
Font[] allFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
font = new Font(allFonts[iteration / 100].getFontName(), Font.PLAIN, 10 * getScale());
System.out.println(allFonts[iteration / 100].getFontName());
}
}
public void render(long timeDelta, Graphics g) {
fontSwitcher();
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("H:mm");
String text = formatter.format(date);
SimpleDateFormat formatter2 = new SimpleDateFormat("ss");
String text2 = formatter2.format(date);
g.setFont(font);
g.setColor(new Color(0, 10 - date.getMinutes() / 6, date.getMinutes() / 6));
//posOffset-=(4*getScale()*timeDelta)/1000000000.0;
g.drawString(text, (int) posOffset, HEIGHT / 2 * getScale());
g.setColor(new Color(10 - date.getSeconds() / 6, date.getSeconds() / 6, 0));
g.drawString(text2, 5, HEIGHT * getScale());
if (posOffset < -g.getFontMetrics().stringWidth(text))
posOffset = 0;
}
}