Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By doWhile

Thread: Draw labyrinth ( I need help)

  1. #1
    ramin is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Draw labyrinth ( I need help)

    Hello!

    I have a big problem with a exercise. its about drawing a labyrinth.
    The question is :

    Write a program that uses the DrawingPanel to draw the following spiral figure:



    The window is 170 pixels wide and 170 pixels tall. The background is white and the foreground is black. The spiral line begins at point (0, 10) and spirals inward. There are 10 pixels between each arm of the spiral. 8 spirals are made in total. The initial spiral touches points (0, 10), (160, 10), (160, 160), (10, 160), and (10, 20).

    For additional challenge, parameterize your program with parameters such as the window size and the number of spiral loops desired.

    plz help me
    Attached Thumbnails Attached Thumbnails Draw labyrinth ( I need help)-draw6.gif  

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Draw labyrinth ( I need help)

    Take a piece of paper and write down the x,y values for the end points for each line to be drawn.
    After you have written several sets of the x,y values, you should be able to see the pattern of how they change as you go towards the center. The pattern should be some arithmetic expression that you can use to compute the next inwards set of lines as you progress towards the center.

    Then write code that uses that pattern to compute the x,y values for the lines and put that code in a loop.

  3. #3
    ramin is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Draw labyrinth ( I need help)

    This is my code that i have written. I know it's wrong beacause the instructions i have tells me to create a static method drawLabyrinth that draws the maze task and set a parameter to the method to set the window size and number of turns in the maze. how do i do that? and do i need to change a lot in my code?

    import java.awt.*;

    public class labyrint {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    DrawingPanel panel = new DrawingPanel(170,170);
    panel.setBackground(Color.WHITE);
    Graphics g = panel.getGraphics();

    g.setColor(Color.BLACK);
    g.drawLine(160 ,10, 0, 10);
    g.drawLine(160 ,160, 160, 10);
    g.drawLine(10 ,160, 160, 160);
    g.drawLine(10 ,20, 10, 160);

    g.drawLine(150 ,20, 10, 20);
    g.drawLine(150 ,150, 150, 20);
    g.drawLine(20 ,150, 150, 150);
    g.drawLine(20 ,30, 20, 150);

    g.drawLine(140 ,30, 20, 30);
    g.drawLine(140 ,140, 140, 30);
    g.drawLine(30 ,140, 140, 140);
    g.drawLine(30 ,40, 30, 140);

    g.drawLine(130 ,40, 30, 40);
    g.drawLine(130 ,130, 130, 40);
    g.drawLine(40 ,130, 130, 130);
    g.drawLine(40 ,50, 40, 130);

    g.drawLine(120 ,50, 40, 50);
    g.drawLine(120 ,120, 120, 50);
    g.drawLine(50 ,120, 120, 120);
    g.drawLine(50 ,60, 50, 120);

    g.drawLine(110 ,60, 50, 60);
    g.drawLine(110 ,110, 110, 60);
    g.drawLine(60 ,110, 110, 110);
    g.drawLine(60 ,70, 60, 110);

    g.drawLine(100 ,70, 60, 70);
    g.drawLine(100 ,100, 100, 70);
    g.drawLine(70 ,100, 100, 100);
    g.drawLine(70 ,80, 70, 100);

    g.drawLine(90 ,80, 70, 80);
    g.drawLine(90 ,90, 90, 80);
    g.drawLine(80 ,90, 90, 90);
    g.drawLine(80 ,90, 80, 90);


    }
    }

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Draw labyrinth ( I need help)

    DarrylBurke likes this.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,611
    Rep Power
    25

    Default Re: Draw labyrinth ( I need help)

    From your posted code:
    g.drawLine(160 ,10, 0, 10);
    ...
    g.drawLine(150 ,20, 10, 20);

    The pattern for those numbers looks like -10 & +10 from the first line to the second line

    Can you find the other patterns?
    Last edited by Norm; 01-04-2012 at 02:29 PM.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,422
    Rep Power
    20

    Default Re: Draw labyrinth ( I need help)

    Quote Originally Posted by doWhile View Post
    Thanks for the heads-up

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. why cant i draw this box???
    By stefandanielsen in forum New To Java
    Replies: 2
    Last Post: 05-12-2011, 03:53 PM
  2. lost in labyrinth.
    By niu_niu in forum New To Java
    Replies: 3
    Last Post: 06-10-2010, 01:39 AM
  3. Draw line
    By janes in forum Java 2D
    Replies: 6
    Last Post: 03-25-2010, 11:48 PM
  4. how to draw an arc
    By Baker in forum New To Java
    Replies: 1
    Last Post: 04-16-2009, 10:05 PM
  5. help me draw... please...
    By kureikougaiji in forum New To Java
    Replies: 1
    Last Post: 01-28-2008, 01:22 PM

Posting Permissions

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