示例#1
0
func imageForScramble(scramble []gocube.Move) []byte {
	cube := gocube.SolvedCubieCube()
	for _, move := range scramble {
		cube.Move(move)
	}

	stickers := cube.StickerCube()
	caption := stringForScramble(scramble)
	image := rubiksimg.GenerateCaptionedImage(666, 33, caption, stickers)

	var output bytes.Buffer
	png.Encode(&output, image)
	return output.Bytes()
}
示例#2
0
func main() {
	if len(os.Args) != 3 && len(os.Args) != 4 {
		dieUsage()
	}

	args := os.Args[1:]
	var caption bool
	if len(args) == 3 {
		if args[0] == "--caption" {
			caption = true
		} else {
			dieUsage()
		}
		args = args[1:]
	}

	cube := gocube.SolvedCubieCube()
	moves, err := gocube.ParseMoves(args[1])
	if err != nil {
		fmt.Fprintln(os.Stderr, "Invalid scramble.")
		os.Exit(1)
	}
	for _, move := range moves {
		cube.Move(move)
	}

	stickers := cube.StickerCube()
	var img image.Image
	if caption {
		img = rubiksimg.GenerateCaptionedImage(1000, 50, args[1], stickers)
	} else {
		img = rubiksimg.GenerateImage(1000, stickers)
	}

	output, err := os.Create(args[0])
	if err != nil {
		fmt.Fprint(os.Stderr, "Failed to open output file:", err)
		os.Exit(1)
	}
	defer output.Close()

	if err := png.Encode(output, img); err != nil {
		fmt.Fprint(os.Stderr, "Failed to encode image:", err)
		os.Exit(1)
	}
}