Results 1 to 2 of 2
  1. #1
    farahm is offline Member
    Join Date
    Nov 2010
    Location
    Beirut, Lebanon
    Posts
    36
    Rep Power
    0

    Default Java, i need help with a recursion base case please

    I'm writing a program that prints Sierpinski's Carpet in a recursive method. I just need to figure out a base case for this method. And one more thing the picture is supposed to have more dots(small squares) in between the squares that don't seem to show in my method. any suggestions are welcomed.
    Java Code:
    import java.awt.*;
     public class Sierpinski{
        public static void main(String args[]) 
        {
            DrawingPanel panel = new DrawingPanel(242,242);
            Graphics g = panel.getGraphics();
            g.setColor(Color.WHITE);
            g.fillRect(0,0,242,242);
            drawGasket(g,0, 0, 243);
        }
    
        public static void drawGasket(Graphics g,int x, int y, int side) {
            int temp= side/3;
            g.setColor(Color.BLACK);
            g.fillRect(x + temp, y + temp, temp - 1, temp - 1);
            if(temp>=3)
            {
                drawGasket(g,x,y,temp);
                drawGasket(g,x+temp,y,temp);
                drawGasket(g,x+2*temp,y,temp);
                drawGasket(g,x,y+temp,temp);
                drawGasket(g,x+2*temp,y+temp,temp);
                drawGasket(g,x,y+2*temp,temp);
                drawGasket(g,x+temp,y+2*temp,temp);
                drawGasket(g,x+2*temp,y+2*temp,temp);
            }
        }
    }
    Last edited by farahm; 04-19-2011 at 12:43 PM.

  2. #2
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    It would be very polite if you supplied the DrawingPanel, making it a SSCEE.
    (Small Self-Contained Executable Example).
    Also use codetags [CODE][/CO DE]and indentation.

Similar Threads

  1. Artificial Intelligence knowledge base in java
    By ala_mages in forum Advanced Java
    Replies: 5
    Last Post: 12-06-2010, 11:44 AM
  2. Problem with case - might need recursion
    By Angelar in forum New To Java
    Replies: 6
    Last Post: 10-13-2010, 03:25 PM
  3. Java with Data Base
    By Nerijus in forum New To Java
    Replies: 9
    Last Post: 05-21-2010, 12:54 PM
  4. How to find logarithm base 2 value in java
    By RJNARESH in forum Advanced Java
    Replies: 5
    Last Post: 03-19-2009, 11:12 PM
  5. Is Java Case Sensitive???? Prove It
    By j2vdk in forum New To Java
    Replies: 53
    Last Post: 09-01-2008, 10:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •