69 lines
1.9 KiB
Java
69 lines
1.9 KiB
Java
package de.zuim.ledcontrol.effects;
|
|
|
|
import de.zuim.ledcontrol.LEDEffect;
|
|
|
|
import java.awt.*;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
|
|
import static de.zuim.ledcontrol.LEDControl.HEIGHT;
|
|
import static de.zuim.ledcontrol.LEDControl.WIDTH;
|
|
|
|
public class AnalogClockEffect implements LEDEffect {
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return "Analog Clock";
|
|
}
|
|
|
|
private int WIDTH = HEIGHT; //make square area for clock
|
|
|
|
long ns = 0;
|
|
boolean upperPart = false;
|
|
|
|
public void render(long timeDelta, Graphics g) {
|
|
//fontSwitcher();
|
|
Calendar time = Calendar.getInstance();
|
|
|
|
double ms = time.get(Calendar.MILLISECOND) / 1000.;
|
|
double sec = time.get(Calendar.SECOND) / 60.;
|
|
double min = time.get(Calendar.MINUTE) / 60.;
|
|
double hour = time.get(Calendar.HOUR_OF_DAY) / 24.;
|
|
|
|
/*g.setColor(new Color(1,1,1));
|
|
g.setFont(new Font("Calibri", Font.BOLD, 19 * getScale()));
|
|
g.drawString(""+time.get(Calendar.SECOND),6,HEIGHT-2);*/
|
|
|
|
//g.setColor(new Color(1,0,0));
|
|
//g.fillArc(0,0,WIDTH-1,HEIGHT-1,0,360);
|
|
//g.setColor(new Color(1,1,1));
|
|
//g.drawArc(0,0,WIDTH-1,HEIGHT-1,0,360);
|
|
for(int i=0; i<12; i++){
|
|
drawHand(i/12.0, 0, new Color(1, 1, 1), g,true);
|
|
}
|
|
|
|
//drawHand(ms, 5, new Color(0, 1, 1), g,false);
|
|
drawHand(sec, 2, new Color(4, 0, 0), g,false);
|
|
drawHand(min, 3, new Color(0, 4, 0), g,false);
|
|
drawHand(hour, 4, new Color(0, 0, 4), g,false);
|
|
|
|
}
|
|
|
|
private void drawHand(double pos, int offset, Color color, Graphics g, boolean marker){
|
|
|
|
pos = (pos+0.75) * 2 * Math.PI;
|
|
|
|
int x = (int) Math.round(((WIDTH-1) / 2. - offset) * Math.cos(pos) + (WIDTH-1) / 2.);
|
|
int y = (int) Math.round(((HEIGHT-1) / 2. - offset) * Math.sin(pos) + (HEIGHT-1) / 2.);
|
|
|
|
g.setColor(color);
|
|
|
|
if(!marker) {
|
|
g.drawLine(WIDTH / 2, HEIGHT / 2, x , y);
|
|
g.setColor(color.brighter().brighter().brighter());
|
|
}
|
|
g.drawRect(x, y, 0, 0);
|
|
}
|
|
}
|