Created
September 13, 2019 07:36
-
-
Save peterhellberg/2fc080891a6b9ee28301d4c4b9610a4c to your computer and use it in GitHub Desktop.
Sudoku board drawn by gfx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"math/rand" | |
"github.com/peterhellberg/gfx" | |
) | |
func main() { | |
board := gfx.NewPaletted(9, 9, gfx.Palette15PDX) | |
line := []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9} | |
rand.Shuffle(len(line), func(i, j int) { | |
line[i], line[j] = line[j], line[i] | |
}) | |
max := board.Bounds().Max | |
rotations := []int{0, 6, 6, 8, 6, 6, 8, 6, 6} | |
for y := 0; y < max.Y; y++ { | |
rotate(line, rotations[y]) | |
for x := 0; x < max.X; x++ { | |
board.SetColorIndex(x, y, line[x]) | |
} | |
o := board.PixOffset(0, y) | |
gfx.Log("%v", board.Pix[o:o+9]) | |
} | |
gfx.SavePNG("/tmp/gfx-sudoku.png", gfx.NewScaledImage(board, 33)) | |
} | |
func rotate(nums []uint8, k int) { | |
k = k % len(nums) | |
if k != 0 { | |
copy(nums, append(nums[len(nums)-k:], nums[:len(nums)-k]...)) | |
} | |
} |
Author
peterhellberg
commented
Sep 13, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment