Добавлен ЛР-1 вариант 8

This commit is contained in:
Victor 2014-02-22 15:15:31 +02:00
parent ca39d89d48
commit 4598326648

56
src/gm/LR_1_v8.java Normal file
View File

@ -0,0 +1,56 @@
package gm;
import com.annimon.graphics.Application;
import com.annimon.graphics.GraphicsExt;
/**
* Вариант 8
* @author aNNiMON
*/
public class LR_1_v8 extends Application {
public static void main(String[] args) {
new LR_1_v8();
}
private static final double[][] ARROW_PTS = {
{0.0, 0.5, 0.4, 0.4, 0.5},
{0.0, 0.00, 0.2, -0.2, 0.00},
};
private static final double N = 30;
public LR_1_v8() {
super(900, 480);
setTitle("LR_1 v8");
}
@Override
protected void paint(GraphicsExt g) {
double x1 = 0, y1 = 2;
for (int i = 0; i < N; i++) {
double x2 = x1 + (i / 50d);
double y2 = y1 + Math.sin(x2) / 5d;
g.reset();
g.translate(x2, y2);
g.rotate(-Math.atan2(y2 - y1, x2 - x1));
drawArrow(g, i);
x1 = x2;
y1 = y2;
}
}
private void drawArrow(GraphicsExt g, int num) {
final int length = ARROW_PTS[0].length;
double[][] points = new double[2][length];
double scale = num / 30d;
for (int i = 0; i < length; i++) {
points[0][i] = ARROW_PTS[0][i] * scale;
points[1][i] = ARROW_PTS[1][i] * scale;
}
g.move(points[0][0], points[1][0]);
for (int i = 1; i < length; i++) {
g.draw(points[0][i], points[1][i]);
}
}
}