Skip to content

Instantly share code, notes, and snippets.

@JohnB
Created October 27, 2011 16:36
Show Gist options
  • Save JohnB/1320074 to your computer and use it in GitHub Desktop.
Save JohnB/1320074 to your computer and use it in GitHub Desktop.
Koch curve for Codify #codify
CODE_FOUND_AT = "https://gist.github.com/1320074        "
CREATED_BY = "      Created by john.bayor@gmail.com"
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