Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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