fogleman / gg

Go Graphics - 2D rendering in Go with a simple API.
https://godoc.org/github.com/fogleman/gg
MIT License
4.46k stars 359 forks source link

Why is the color of the intersection darker? #154

Closed IamHuskar closed 2 years ago

IamHuskar commented 2 years ago

func main() { dc := gg.NewContext(800, 800) dc.Scale(80,80) dc.SetRGBA(1, 1, 1, 1) dc.Clear() dc.SetRGB(1, 0, 0) dc.SetLineWidth(1) dc.MoveTo(0, 1) dc.LineTo(1, 1) dc.MoveTo(1, 1) dc.LineTo(1, 0) dc.MoveTo(0.1, 0.1) dc.LineTo(1, 0.1) dc.MoveTo(0.1, 0.1) dc.LineTo(0.1, 1) dc.DrawRectangle(0.2, 0.2, 0.5, 0.5) dc.Stroke() dc.SavePNG("out.png") }

Why is the color of the intersection darker? image

SetRGB(1, 0, 0) looks like a little lighter than the real 0XFF0000 color?

image

IamHuskar commented 2 years ago

if I only use go/image lib it's ok image func main() { const ( dx = 300 dy = 500 )

 imgcounter := 123
 imgfile, _ := os.Create(fmt.Sprintf("%03d.png", imgcounter))
 defer imgfile.Close()

 img := image.NewNRGBA(image.Rect(0, 0, dx, dy))

 for y := 0; y < dy; y++ {
    for x := 0; x < dx; x++ {

        if x%8 == 0 {

             img.Set(x, y, color.RGBA{255, 0, 0, 255})
        }
    }
 }

err := png.Encode(imgfile, img)
 if err != nil {
    log.Fatal(err)
 }

}