Search code examples
javaprocessinggraphics2d

new line when i display 10 ellipse


I am new in processing and java, I have some exercise to display 100 ellipses but the screen size is (900, 600), and I want break 100 in 10 lines of 10, but I don't know how to break line in processing , I already use translate(https://processing.org/reference/translate_.html),but it doesn't work.

  //function
  void draw(){
    smooth();
    noStroke();
    fill(23,43,208,200);// cor azul
    ellipse(posX,posY,12,10);

    noStroke();
    fill(242,76,39);//cor vermelho
    ellipse(posX,posY,12,10);

  }


  for (int i=1; i<ellipses.length; i++)
  {
    for (int j=i; j<ellipses.length; j++)
     {
          if(j%10==0)
          ellipses[i].draw();//calling function
     } 
  }

Solution

  • import javafx.application.Application;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.shape.Ellipse;
    import javafx.stage.Stage;
    
    public class T15DrawEllipses extends Application {
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) throws Exception {
            Group group = new Group();
            Scene scene = new Scene(group, 900, 600);
    
            for (int row = 0; row < 10; row++) {
                for (int col = 0; col < 10; col++) {
                    Ellipse e = new Ellipse();
                    e.setCenterX(44 + col * 90);
                    e.setCenterY(29 + row * 60);
                    e.setRadiusX(45);
                    e.setRadiusY(30);
                    group.getChildren().add(e);
                }
            }
            primaryStage.setScene(scene);
            primaryStage.show();
        }
    }
    

    A complete example of 10 rows/columns with ellipses.