48 lines
676 B
Go
48 lines
676 B
Go
package semantices
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
"image/png"
|
|
"os"
|
|
)
|
|
|
|
const (
|
|
Width = 800
|
|
Height = 600
|
|
)
|
|
|
|
var img *image.RGBA
|
|
|
|
func InitCanvas() {
|
|
img = image.NewRGBA(image.Rect(0, 0, Width, Height))
|
|
white := color.RGBA{255, 255, 255, 255}
|
|
for y := 0; y < Height; y++ {
|
|
for x := 0; x < Width; x++ {
|
|
img.Set(x, y, white)
|
|
}
|
|
}
|
|
}
|
|
|
|
func DrawPixel(x, y int) {
|
|
if img == nil {
|
|
return
|
|
}
|
|
if x < 0 || x >= Width || y < 0 || y >= Height {
|
|
return
|
|
}
|
|
img.Set(x, y, color.Black)
|
|
}
|
|
|
|
func SavePNG(filename string) error {
|
|
if img == nil {
|
|
return nil
|
|
}
|
|
f, err := os.Create(filename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
return png.Encode(f, img)
|
|
}
|