如何跳过特定的循环循环?

问题描述

我想创建这样一个形状。

enter image description here

只需画一个 Circle,然后画一个 Lines

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Stage;

public class SkipPartsOfCycle extends Application {

    @Override
    public void start(Stage stage) {
        var pane = new Pane();
        pane.getChildren().add(new Circle(500,500,100,Color.GREEN));
        drawLine(pane,20,5);
        drawLine(pane,70,110,160,200,250,290,340,360,5);
        stage.setScene(new Scene(pane,1000,1000));
        stage.show();
    }

    public static void drawLine (Pane pane,int start,int end,int increment) {
        for (var i = start; i <= end; i += increment) {
            pane.getChildren().add(new Line(500,500 + (100 * Math.sin(Math.toRadians(i))),500 + (100 * Math.cos(Math.toRadians(i)))));
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

此代码有效。问题是要跳过循环的特定部分,我会在特定范围内多次调用它。另一种解决方案是将条件插入循环中,但会不必要地复杂化。

最大的问题是,由于我多次调用它,因此在更改时(例如 0-30,60-120,150-210,240-300,330-360)需要修改所有方法调用,而不仅仅是一个。

请问有更简单的解决方案吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)