Jump to content
Science Forums

Recursive Fractal

Recommended Posts

hello everybody


I am writing a program in java that draws a square fractal recursively. The program starts by drawing a rectangle in the center of the window (1/4 of the window). Then I need to draw 4 smaller rectangles attached to the corners of the first rectangle. Then I need to draw 3 smaller rectangles attached to the corners to the corners of the previous rectangle and so on until it reaches to 1 pixel. Each one of the succeeding rectangles is half the width and height or the preceding rectangle. The output should be like the picture at the end of the post




I am new to computer science so please help even with a pseudo code that can explain the steps and calculations to draw the rectangles.


thank you in advance

Link to comment
Share on other sites

Welcome to hypography, Mahdi! :)


Some simple pseudocode:

 if Depth<=MaxDepth {
   Rectangle (Top,Left)-(Top+Length,Left+Length,Depth+1,MaxDepth)

Replace "whatever" with an integer for how "deep" you want the fractal image to be: 1 draws 1 box, 2 draws 5 boxes, 3 draws 17 visible boxes, 4 draws 53, etc.


The existence of a primitive rectangle drawing command, "Rectangle", is assumed.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...