1 Attachment(s)
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:
http://www.cs.washington.edu/educati...heck/Draw6.gif
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
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.
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);
}
}
Re: Draw labyrinth ( I need help)
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?
Re: Draw labyrinth ( I need help)
Quote:
Originally Posted by
doWhile
Thanks for the heads-up
db