Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
import java.awt.Canvas;
import java.awt.Graphics;
import javax.swing.JFrame;
public class Aufgabe15 extends Canvas {
/**
*
*/
private static final long serialVersionUID = 1L;
private char afg = 'a';
private int wx = 50;
private int hy = 50;
private int n = 3;
private int r = 100;
private int x_centre = 250;
private int y_centre = 250;
public Aufgabe15 next() {
afg++;
if (afg > 'c') {
afg = 'a';
n++;
}
return this;
}
@Override
public void paint(Graphics g) {
super.paint(g);
switch (afg) {
case 'a':
int x = 0;
int y = this.getHeight();
for (int i = 0; i < 100; i++) {
int x2 = x;
int y2 = y - hy;
g.drawLine(x, y, x2, y2);
y = y2;
x2 = x2 + wx;
g.drawLine(x, y, x2, y2);
x = x2;
}
break;
case 'b':
for (int i = 0; i < n; i++) {
float xn = (float) (r * Math.cos(2 * Math.PI * i / n) + x_centre);
float yn = (float) (r * Math.sin(2 * Math.PI * i / n) + y_centre);
float xn2 = (float) (r * Math.cos(2 * Math.PI * (i + 1) / n) + x_centre);
float yn2 = (float) (r * Math.sin(2 * Math.PI * (i + 1) / n) + y_centre);
g.drawLine((int) xn, (int) yn, (int) xn2, (int) yn2);
}
break;
case 'c':
for (int j = 0; j < n; j++) {
float theta = (float) (Math.PI * j / (2 * n));
for (int i = 0; i < n; i++) {
float xn = (float) (r * Math.cos(2 * Math.PI * i / n + theta) + x_centre);
float yn = (float) (r * Math.sin(2 * Math.PI * i / n + theta) + y_centre);
float xn2 = (float) (r * Math.cos(2 * Math.PI * (i + 1) / n + theta) + x_centre);
float yn2 = (float) (r * Math.sin(2 * Math.PI * (i + 1) / n + theta) + y_centre);
g.drawLine((int) xn, (int) yn, (int) xn2, (int) yn2);
}
}
break;
default:
break;
}
}
(leider net erlaubt...)