Created
September 15, 2011 15:43
-
-
Save himerzi/1219606 to your computer and use it in GitHub Desktop.
This code draws a box fractal (http://mathworld.wolfram.com/BoxFractal.html)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Michael Detmold | |
//A program that draws a box fractal | |
import org.learninggroovy.graphicswindow.GraphicsWindow | |
import java.awt.* | |
window = GraphicsWindow.getBlankWindow(700,700) | |
def ss = 5,dims = 670 | |
def sx =ss,sy =ss | |
ite = 7 | |
fract(sx,sy,dims,0) | |
def fract(x, y, side, i){ | |
if(i==ite){ | |
}else{ | |
int smallSide = side/3 | |
int count = i | |
count++ | |
//ul = "upper left" | |
fract(x,y,smallSide,count) | |
//ur | |
fract(x+(smallSide*2),y,smallSide,count) | |
//ll | |
fract(x,y+(smallSide*2),smallSide,count) | |
//lr | |
fract(x+(smallSide*2),y+(smallSide*2),smallSide,count) | |
//cent | |
fract(x+(smallSide),y+(smallSide),smallSide,count) | |
if(i== ite-1){ //ensures only the smalles squares are drawn | |
window.draw { g-> | |
g.drawRect(x,y,side,side) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment