Created
October 27, 2011 16:36
-
-
Save JohnB/1320074 to your computer and use it in GitHub Desktop.
Koch curve for Codify #codify
This file contains hidden or 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
CODE_FOUND_AT = "https://gist.github.com/1320074 " | |
CREATED_BY = " Created by [email protected]" | |
LONGLINE = 630 | |
-- Use this function to perform your initial setup | |
function setup() | |
print(string.format(CODE_FOUND_AT..CREATED_BY)) | |
iparameter("dimension",0,5) | |
iparameter("sides",3,6) | |
lentab = {0,0, 630, 500, 450, 450 } | |
dirtab = {0,0, -120, -90, -72, -60} | |
end | |
-- This function gets called once every frame | |
function draw() | |
background(155, 197, 49, 255) | |
stroke(62, 50, 198, 255) | |
strokeWidth(4) | |
translate((WIDTH-LONGLINE)*0.5,HEIGHT*0.75) | |
for i = 1, sides do | |
koch(dimension, lentab[sides]) | |
rotate(dirtab[sides]) | |
end | |
end | |
function koch(level, len) | |
if level == 0 | |
then | |
line(0,0,len,0) | |
translate(len,0) | |
else | |
koch(level-1,len/3) | |
rotate(60) | |
koch(level-1,len/3) | |
rotate(-120) | |
koch(level-1,len/3) | |
rotate(60) | |
koch(level-1,len/3) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment