This is a type cast. It notifies the compiler that
it is OK to convert the floating point value to its right into an
int
.
Here is the complete program that draws a single star in the center of the rectangle.
There is nothing recursive about it yet. This will come next.
import javax.swing.*; import java.awt.* ; import java.lang.Math ; class SnowFlakePanel extends JPanel { public SnowFlakePanel() { setPreferredSize( new Dimension(400, 400) ); setBackground( Color.white ); } private void drawStar( Graphics gr, int x, int y, int size ) { int endX, endY ; // Six lines radiating from (x,y) for ( int i = 0; i<6; i++ ) { endX = x + (int)(size*Math.cos( (2*Math.PI/6)*i )); endY = y + (int)(size*Math.sin( (2*Math.PI/6)*i )); gr.drawLine( x, y, endX, endY ); } } public void paintComponent ( Graphics gr ) { int width = getWidth(); int height = getHeight(); int min; super.paintComponent( gr ); setBackground(Color.white); gr.setColor( Color.blue ); if ( height > width ) min = height; else min = width; drawStar( gr, width/2, height/2, min/4 ); } } public class SnowFlakeBasic { public static void main ( String[] args ) { JFrame frame = new JFrame( "Snowflake Basic" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.getContentPane().add( new SnowFlakePanel() ); frame.pack(); frame.setVisible( true ); } }
To draw the snowflake, draw little stars at the ends of the six lines that make the big star. Do you already know where these locations are?
Hint: look inside the loop in drawStar