Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sudoku board drawn by gfx
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]...))
}
}
@peterhellberg

This comment has been minimized.

Copy link
Owner Author

peterhellberg commented Sep 13, 2019

gfx-sudoku

@peterhellberg

This comment has been minimized.

Copy link
Owner Author

peterhellberg commented Sep 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.