kopia lustrzana https://github.com/jameshball/osci-render
Implemeted ellipse rotation
rodzic
e5460bf096
commit
dd24a19447
|
@ -14,7 +14,8 @@ public class AudioClient {
|
||||||
AudioPlayer.FORMAT = AudioPlayer.defaultFormat(SAMPLE_RATE);
|
AudioPlayer.FORMAT = AudioPlayer.defaultFormat(SAMPLE_RATE);
|
||||||
|
|
||||||
AudioPlayer.addShapes(Shapes.generatePolygram(5, 3, 0.5, 60));
|
AudioPlayer.addShapes(Shapes.generatePolygram(5, 3, 0.5, 60));
|
||||||
AudioPlayer.addShape(new Ellipse(0.7, 0.7));
|
//AudioPlayer.addShapes(Shapes.generatePolygon(500, 0.5, 10));
|
||||||
|
AudioPlayer.addShape(new Ellipse(0.5, 1));
|
||||||
|
|
||||||
AudioPlayer.setRotateSpeed(0.8);
|
AudioPlayer.setRotateSpeed(0.8);
|
||||||
AudioPlayer.setTranslation(2, new Vector(0.5, 0.5));
|
AudioPlayer.setTranslation(2, new Vector(0.5, 0.5));
|
||||||
|
|
|
@ -5,50 +5,58 @@ public class Ellipse implements Shape {
|
||||||
private final double b;
|
private final double b;
|
||||||
private final double weight;
|
private final double weight;
|
||||||
private final double length;
|
private final double length;
|
||||||
|
private final double rotation;
|
||||||
private final Vector position;
|
private final Vector position;
|
||||||
|
|
||||||
public Ellipse(double a, double b, double weight, Vector position) {
|
public Ellipse(double a, double b, double weight, double rotation, Vector position) {
|
||||||
this.a = a;
|
this.a = a;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
|
this.rotation = rotation;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
// Approximation of length.
|
// Approximation of length.
|
||||||
this.length = 2 * Math.PI * Math.sqrt((this.a * this.a + this.b * this.b) / 2);
|
this.length = 2 * Math.PI * Math.sqrt((this.a * this.a + this.b * this.b) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ellipse(double a, double b, Vector position) {
|
public Ellipse(double a, double b, Vector position) {
|
||||||
this(a, b, 100, position);
|
this(a, b, 100, 0, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ellipse(double a, double b) {
|
public Ellipse(double a, double b) {
|
||||||
this(a, b, 100, new Vector());
|
this(a, b, 100, 0, new Vector());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float nextX(double drawingProgress) {
|
public float nextX(double drawingProgress) {
|
||||||
return (float) (position.getX() + a * Math.sin(2 * Math.PI * drawingProgress));
|
return (float) (position.getX()
|
||||||
|
+ a * Math.cos(2 * Math.PI * drawingProgress) * Math.cos(rotation)
|
||||||
|
- b * Math.sin(2 * Math.PI * drawingProgress) * Math.sin(rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float nextY(double drawingProgress) {
|
public float nextY(double drawingProgress) {
|
||||||
return (float) (position.getY() + b * Math.cos(2 * Math.PI * drawingProgress));
|
return (float) (position.getY()
|
||||||
|
+ a * Math.cos(2 * Math.PI * drawingProgress) * Math.sin(rotation)
|
||||||
|
+ b * Math.sin(2 * Math.PI * drawingProgress) * Math.cos(rotation));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement ellipse rotation.
|
|
||||||
@Override
|
@Override
|
||||||
public Shape rotate(double theta) {
|
public Shape rotate(double theta) {
|
||||||
return this;
|
if (theta + rotation > 2 * Math.PI) {
|
||||||
|
theta -= 2 * Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Ellipse(a, b, weight, theta, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Shape scale(double factor) {
|
public Shape scale(double factor) {
|
||||||
return new Ellipse(a * factor, b * factor, weight, position.scale(factor));
|
return new Ellipse(a * factor, b * factor, weight, rotation, position.scale(factor));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement ellipse translation.
|
|
||||||
@Override
|
@Override
|
||||||
public Shape translate(Vector vector) {
|
public Shape translate(Vector vector) {
|
||||||
return new Ellipse(a, b, weight, position.add(vector));
|
return new Ellipse(a, b, weight, rotation, position.add(vector));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Ładowanie…
Reference in New Issue