From 8bf4eb7613590baa9ce7f41e4de6e23b3afac578 Mon Sep 17 00:00:00 2001 From: James Ball Date: Wed, 29 Jan 2020 20:34:02 +0000 Subject: [PATCH] Added support for drawing 'polygrams' --- src/AudioClient.java | 26 +++++--------------------- src/Shapes.java | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 src/Shapes.java diff --git a/src/AudioClient.java b/src/AudioClient.java index ca350c4..a12fb03 100644 --- a/src/AudioClient.java +++ b/src/AudioClient.java @@ -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 generatePolygon(int sides, double scale) { - List 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; - } } \ No newline at end of file diff --git a/src/Shapes.java b/src/Shapes.java new file mode 100644 index 0000000..f44b323 --- /dev/null +++ b/src/Shapes.java @@ -0,0 +1,34 @@ +import java.util.ArrayList; +import java.util.List; + +public class Shapes { + public static List generatePolygram(int sides, int angleJump, Point start) { + List 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 generatePolygram(int sides, int angleJump, double scale) { + return generatePolygram(sides, angleJump, new Point(scale, scale)); + } + + public static List generatePolygon(int sides, Point start) { + return generatePolygram(sides, 2, start); + } + + public static List generatePolygon(int sides, double scale) { + return generatePolygon(sides, new Point(scale, scale)); + } +}