Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created September 13, 2019 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhellberg/2fc080891a6b9ee28301d4c4b9610a4c to your computer and use it in GitHub Desktop.
Save peterhellberg/2fc080891a6b9ee28301d4c4b9610a4c to your computer and use it in GitHub Desktop.
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
Copy link
Author

gfx-sudoku

@peterhellberg
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment