kopia lustrzana https://github.com/jameshball/osci-render
Added generic polygon drawing
rodzic
33f867dba4
commit
d2c668d057
|
@ -10,17 +10,9 @@ public class AudioClient {
|
|||
AudioPlayer player = new AudioPlayer();
|
||||
AudioPlayer.FORMAT = new XtFormat(new XtMix(sampleRate, XtSample.FLOAT32), 0, 0, 2, 0);
|
||||
|
||||
// Draws a square.
|
||||
Line l1 = new Line(-0.5, -0.5, 0.5, -0.5);
|
||||
Line l2 = new Line(0.5, -0.5, 0.5, 0.5);
|
||||
Line l3 = new Line(0.5, 0.5, -0.5, 0.5);
|
||||
Line l4 = new Line(-0.5, 0.5, -0.5, -0.5);
|
||||
|
||||
AudioPlayer.addLine(l1);
|
||||
AudioPlayer.addLine(l2);
|
||||
AudioPlayer.addLine(l3);
|
||||
AudioPlayer.addLine(l4);
|
||||
|
||||
for (int i = 2; i < 7; i++) {
|
||||
AudioPlayer.addLines(generatePolygon(i, 0.5));
|
||||
}
|
||||
AudioPlayer.setRotateSpeed(0.4);
|
||||
|
||||
player.start();
|
||||
|
@ -32,8 +24,19 @@ public class AudioClient {
|
|||
public static List<Line> generatePolygon(int sides, double scale) {
|
||||
List<Line> polygon = new ArrayList<>();
|
||||
|
||||
Point start = new Point(scale, scale);
|
||||
double theta = 2 * Math.PI / sides;
|
||||
|
||||
return null;
|
||||
Point start = new Point(scale, scale);
|
||||
Point rotated = start.rotate(theta);
|
||||
|
||||
polygon.add(new Line(start, rotated));
|
||||
|
||||
while (!rotated.equals(start)) {
|
||||
polygon.add(new Line(rotated.copy(), rotated.rotate(theta)));
|
||||
|
||||
rotated = rotated.rotate(theta);
|
||||
}
|
||||
|
||||
return polygon;
|
||||
}
|
||||
}
|
|
@ -53,6 +53,10 @@ public class AudioPlayer extends Thread {
|
|||
AudioPlayer.lines.add(line);
|
||||
}
|
||||
|
||||
public static void addLines(List<Line> lines) {
|
||||
AudioPlayer.lines.addAll(lines);
|
||||
}
|
||||
|
||||
private static Line currentLine() {
|
||||
return lines.get(currentLine % lines.size());
|
||||
}
|
||||
|
|
|
@ -20,6 +20,10 @@ public class Line {
|
|||
return new Line(getA().rotate(theta), getB().rotate(theta));
|
||||
}
|
||||
|
||||
public Line copy() {
|
||||
return new Line(getA().copy(), getB().copy());
|
||||
}
|
||||
|
||||
public Point getA() {
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -38,14 +38,15 @@ public class Point {
|
|||
}
|
||||
}
|
||||
|
||||
public Point copy() {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public Point rotate(double theta) {
|
||||
double oldX = getX();
|
||||
double oldY = getY();
|
||||
Point point = new Point(getX(), getY());
|
||||
|
||||
Point point = new Point(oldX, oldY);
|
||||
|
||||
point.setX(oldX * Math.cos(theta) - oldY * Math.sin(theta));
|
||||
point.setY(oldX * Math.sin(theta) + oldY * Math.cos(theta));
|
||||
point.setX(getX() * Math.cos(theta) - getY() * Math.sin(theta));
|
||||
point.setY(getX() * Math.sin(theta) + getY() * Math.cos(theta));
|
||||
|
||||
return point;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue