// Requires "go mod init main" and "go get github.com/holizz/terrapin" after // You may need to install git first: https://git-scm.com/ package main import ( "github.com/holizz/terrapin" "image" "image/png" "math" "os" ) func kochCurve(t *terrapin.Terrapin, lung float64, liv int) { if liv == 0 { t.Forward(lung) } else { kochCurve(t, lung / 3, liv - 1) t.Left(math.Pi / 3.0) kochCurve(t, lung / 3, liv - 1) t.Right(2.0 * math.Pi / 3.0) kochCurve(t, lung/ 3, liv - 1) t.Left(math.Pi / 3.0) kochCurve(t, lung / 3, liv - 1) } } func kochSnowflake(t *terrapin.Terrapin, lung float64, liv int) { kochCurve(t, lung, liv) t.Right(2.0 * math.Pi / 3.0) kochCurve(t, lung, liv) t.Right(2.0 * math.Pi / 3.0) kochCurve(t, lung, liv) t.Right(2.0 * math.Pi / 3.0) } func main() { i := image.NewRGBA(image.Rect(0, 0, 1000, 1000)) t := terrapin.NewTerrapin(i, terrapin.Position{200.0, 800.0}) kochSnowflake(t, 500.0, 5) png.Encode(os.Stdout, i) }