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

55 lines
1.2 KiB
Java

package de.zuim.ledcontrol.effects;
import de.zuim.ledcontrol.LEDEffect;
import java.awt.*;
import java.util.Random;
import static de.zuim.ledcontrol.LEDControl.HEIGHT;
import static de.zuim.ledcontrol.LEDControl.WIDTH;
public class SineEffect implements LEDEffect {
private final Random r = new Random();
private final double[][] seeds = new double[10][7];
@Override
public void load() {
for (double[] seed : seeds) {
for (int i = 0; i < seed.length; i++) {
seed[i] = r.nextDouble();
}
}
}
double steps = 0;
@Override
public void render(long timeDelta, Graphics g) {
steps += timeDelta * 0.000000001;
for (int i = 0; i < 6; i++) {
g.setColor(new Color((int) (15 * seeds[i][0]), (int) (10 * seeds[i][3]), (int) (4 * seeds[i][4])));
for (int x = 0; x < WIDTH * getScale(); x++) {
g.drawLine(x, calc(i, x), x + 1, calc(i, x + 1));
}
}
}
private int calc(int i, int x) {
return (int) (Math.sin(((x + 2 * seeds[i][2]) * 0.5 * seeds[i][1]) / getScale() + steps * seeds[i][6]) * 7 * getScale() * (seeds[i][5] + 0.2) + (getScale() * HEIGHT) / 2);
}
@Override
public String getDescription() {
return "SineEffect";
}
@Override
public int getScale() {
return 1;
}
}