Skip to content

Instantly share code, notes, and snippets.

@akhikhl
Created February 10, 2014 16:44
Show Gist options
  • Save akhikhl/8919483 to your computer and use it in GitHub Desktop.
Save akhikhl/8919483 to your computer and use it in GitHub Desktop.
Sierpinsky Triangle
learn triangle $x {
fw $x
tr 120
fw $x
tr 120
fw $x
tr 120
}
learn serpinsky $x, $level {
triangle $x
pu
fw $x/2
tr 60
pd
serpinsky1 $x/2, $level
}
learn serpinsky1 $x, $level {
if $level == 0 {
return
}
triangle $x
pu
tl 60
fw $x/2
tr 60
pd
serpinsky1 $x/2, $level - 1
pu
tr 60
fw $x
tl 60
pd
serpinsky1 $x/2, $level - 1
pu
tr 180
fw $x
tl 180
pd
serpinsky1 $x/2, $level - 1
pu
tl 60
fw $x/2
tr 60
pd
}
$level = 7
reset
go 120, 0
print "Serpinsky carpet level " + $level
pu
go 0, 400
pd
dir 30
serpinsky 400, $level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment