尝试使用 2 条弧线制作彩虹,并使用 FXgraphics2D drawArc 和 drawLine 函数填充之间的线条
尝试使用 2 条弧线制作彩虹,并使用 FXgraphics2D drawArc 和 drawLine 函数填充之间的线条。它没有按预期工作。任务是制作一条以红色开始和结束的彩虹,显示其中的色调光谱。
请求的结果:
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);
}
}
绘制弧线很高兴,但填充弧线之间的线条给了我麻烦。我也不确定角度变量的值应该是多少以及如何获得正确的颜色值。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论