go to previous page   go to home page   go to next page

Answer:

A Koch snowflake.


Snowflake

Koch Snowflake
Click on the Snowflake

Here is a class that creates a Koch snowflake. It uses the same KLine class as above. The three lines are drawn in sequence, clockwise, so the bump is on the left of each line.

 

public class Koch extends Application
{ 

  public void start(Stage stage) 
  { 
    double sceneWidth=400, sceneHeight=400;
    
    // Vertices of a triangle in the center of the screen
    double x0 = sceneWidth*0.1, y0 = sceneHeight*0.74;
    double x1 = sceneWidth*0.5, y1 = sceneHeight*0.04;
    double x2 = sceneWidth*0.9, y2 = sceneHeight*0.74;
    
    // Construct a triangle with three Koch lines for sides    
    KLine left   = new KLine( x0, y0, x1, y1 );
    KLine right  = new KLine( x1, y1, x2, y2 );
    KLine bottom = new KLine( x2, y2, x0, y0 );

    // Add the triangle to the scene
    Group  root = new Group( );   
    root.getChildren().addAll( left, right, bottom );        
    Scene scene = new Scene(root, sceneWidth, sceneHeight, Color.HONEYDEW ); 
    
    // Set the scene
    stage.setTitle("Koch Snowflake"); 
    stage.setScene(scene); 
    stage.show(); 
  }      

}

If you change the order the lines are drawn, or change some things in KLine, you get other amusing pictures.


QUESTION 16:

Change the order of the lines from clockwise to counter-clockwise.


go to previous page   go to home page   go to next page