希尔伯特曲线 java_Java中空间填充Hilbert曲线的递推算法
我正在學(xué)習(xí)用
Java編寫代碼,我已經(jīng)學(xué)習(xí)了java編程的遞歸部分.我理解了遞歸方法的基礎(chǔ)知識(shí),并且我正在嘗試編寫填充希爾伯特曲線(和Levy C曲線)的空間,到目前為止,一切都順利進(jìn)行,直到實(shí)際的遞歸部分.我在提出遞歸方法時(shí)遇到了麻煩,想知道是否有人可以幫助我.我也知道它需要在DrawHilbert方法中.
public class HilbertCurve extends JPanel {
int N;
/**
* Constructor for Hilbert Curve
*/
public HilbertCurve ()
{
Scanner myKeyboard = new Scanner(System.in);
System.out.println("Enter an integer number to indicate the level of recursive depth: ");
N = myKeyboard.nextInt();
// Create a JFrame - a window that will appear on your screen
JFrame f = new JFrame();
// Tells the program to quit if you close the window
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Puts your drawing into the window (the JFrame)
f.add(new JScrollPane(this));
// Changes the size of the window on the screen
f.setSize(600, 600);
// Changes where the window will appear on your screen
f.setLocation(200, 200);
// Makes the window appear
f.setVisible(true);
}
public void setupHilbert (Turtle turtle)
{
turtle.penup();
turtle.setXY(0,0);
// draw a simple rectangle that is 100x50 pixels
turtle.pendown();
drawHilbert(turtle, N);
}
public void drawHilbert(Turtle turtle, int n) {
if (n == 0) return;
turtle.changeColor(Color.GREEN);
turtle.changeWidth(2);
turtle.left(-90);
turtle.forward(100);
turtle.left(90);
turtle.forward(100);
turtle.left(90);
turtle.forward(100);
turtle.left(-90);
turtle.penup();
}
protected void paintComponent(Graphics g)
{
Turtle turtle = new Turtle((Graphics2D) g, getBounds());
turtle.setHeadingMode(Turtle.DEGREE);
setupHilbert(turtle);
}
// plot a Hilbert curve of order N
public static void main(String[] args)
{
Scanner myKeyboard = new Scanner(System.in);
HilbertCurve test = new HilbertCurve();
}
}
總結(jié)
以上是生活随笔為你收集整理的希尔伯特曲线 java_Java中空间填充Hilbert曲线的递推算法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: JAVA实现可视化的xpath_Java
- 下一篇: 航空购票系统源码java_航空售票系统