Trying to make a rainbow using 2 arcs and filling the lines between with the FXgraphics2D drawArc and drawLine functions. Its not working as expected. The assignment is to make a rainbow starting and ending with red displaying the huespectrum within it.
The requested result:
public class Rainbow extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Canvas canvas = new Canvas(1920, 1080);
draw(new FXGraphics2D(canvas.getGraphicsContext2D()));
primaryStage.setScene(new Scene(new Group(canvas)));
primaryStage.setTitle("Rainbow");
primaryStage.show();
}
public void draw(FXGraphics2D g2d) {
int radiusBuiten = 1000;
int radiusBinnen = radiusBuiten/2;
for (int i = 0; i < 180; i++) {
g2d.drawArc(0, 0, radiusBuiten, radiusBuiten, 0, i);
g2d.drawArc(radiusBinnen/2, radiusBinnen/2, radiusBinnen, radiusBinnen, 0, i);
float hoek = i;
double x1 = radiusBinnen * Math.cos(hoek);
double y1 = radiusBinnen * Math.sin(hoek);
double x2 = radiusBuiten * Math.cos(hoek);
double y2 = radiusBuiten * Math.sin(hoek);
g2d.setColor(Color.getHSBColor(i/500.0f, 1, 1));
g2d.draw(new Line2D.Double((int)x1,(int)y1, (int)x2, (int)y2));
}
}
public static void main(String[] args) {
launch(Rainbow.class);
}
}
Drawing the arcs is going as pleased but filling in the lines between the arcs is giving me trouble. Im also not sure what the value should be for the angle variabel and how to get the correct color values.