func Example() { // Create a Hilbert curve for mapping to and from a 16 by 16 space. s, _ := hilbert.NewHilbert(16) // Create a Peano curve for mapping to and from a 27 by 27 space. //s, _ := hilbert.NewPeano(27) // Now map one dimension numbers in the range [0, N*N-1], to an x,y // coordinate on the curve where both x and y are in the range [0, N-1]. x, y, _ := s.Map(96) // Also map back from (x,y) to t. t, _ := s.MapInverse(x, y) fmt.Printf("x = %d, y = %d, t = %d\n", x, y, t) // Output: // x = 4, y = 12, t = 96 }
func main() { setupDraw2D() newHilbert := func(n int) hilbert.SpaceFilling { s, err := hilbert.NewHilbert(int(math.Pow(2, float64(n)))) if err != nil { panic(fmt.Errorf("failed to create hilbert space: %s", err.Error())) } return s } newPeano := func(n int) hilbert.SpaceFilling { s, err := hilbert.NewPeano(int(math.Pow(3, float64(n)))) if err != nil { panic(fmt.Errorf("failed to create peano space: %s", err.Error())) } return s } if err := mainDrawOne("hilbert.png", newHilbert(3)); err != nil { log.Fatalf("Failed to draw image: %s", err.Error()) } if err := mainDrawAnimation("hilbert_animation.gif", newHilbert, 1, 8); err != nil { log.Fatalf("Failed to draw animation: %s", err.Error()) } if err := mainDrawOne("peano.png", newPeano(2)); err != nil { log.Fatalf("Failed to draw image: %s", err.Error()) } if err := mainDrawAnimation("peano_animation.gif", newPeano, 1, 6); err != nil { log.Fatalf("Failed to draw animation: %s", err.Error()) } }