Added support for drawing 'polygrams'

pull/35/head
James Ball 2020-01-29 20:34:02 +00:00
rodzic d2c668d057
commit 8bf4eb7613
2 zmienionych plików z 39 dodań i 21 usunięć

Wyświetl plik

@ -11,32 +11,16 @@ public class AudioClient {
AudioPlayer.FORMAT = new XtFormat(new XtMix(sampleRate, XtSample.FLOAT32), 0, 0, 2, 0);
for (int i = 2; i < 7; i++) {
AudioPlayer.addLines(generatePolygon(i, 0.5));
AudioPlayer.addLines(Shapes.generatePolygon(i, 0.5));
}
AudioPlayer.setRotateSpeed(0.4);
//AudioPlayer.addLines(Shapes.generatePolygram(5, 4, new Point(0, 0.4).rotate(Math.PI / 5)));
AudioPlayer.setRotateSpeed(0.8);
player.start();
while (true) {
}
}
public static List<Line> generatePolygon(int sides, double scale) {
List<Line> polygon = new ArrayList<>();
double theta = 2 * Math.PI / sides;
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;
}
}

34
src/Shapes.java 100644
Wyświetl plik

@ -0,0 +1,34 @@
import java.util.ArrayList;
import java.util.List;
public class Shapes {
public static List<Line> generatePolygram(int sides, int angleJump, Point start) {
List<Line> polygon = new ArrayList<>();
double theta = angleJump * Math.PI / sides;
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;
}
public static List<Line> generatePolygram(int sides, int angleJump, double scale) {
return generatePolygram(sides, angleJump, new Point(scale, scale));
}
public static List<Line> generatePolygon(int sides, Point start) {
return generatePolygram(sides, 2, start);
}
public static List<Line> generatePolygon(int sides, double scale) {
return generatePolygon(sides, new Point(scale, scale));
}
}