This repository has been archived on 2026-05-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
sfdl/semantices/draw.go
2025-12-04 18:44:37 +08:00

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)
}