github.com/xxf098/lite-proxy@v0.15.1-0.20230422081941-12c69f323218/web/render/context_test.go (about)

     1  package render
     2  
     3  import (
     4  	"math/rand"
     5  	"testing"
     6  )
     7  
     8  func TestDrawLine(t *testing.T) {
     9  	const W = 1024
    10  	const H = 1024
    11  	dc := NewContext(W, H)
    12  	dc.SetRGB(0, 0, 0)
    13  	dc.Clear()
    14  	for i := 0; i < 1000; i++ {
    15  		x1 := rand.Float64() * W
    16  		y1 := rand.Float64() * H
    17  		x2 := rand.Float64() * W
    18  		y2 := rand.Float64() * H
    19  		r := rand.Float64()
    20  		g := rand.Float64()
    21  		b := rand.Float64()
    22  		a := rand.Float64()*0.5 + 0.5
    23  		w := rand.Float64()*4 + 1
    24  		dc.SetRGBA(r, g, b, a)
    25  		dc.SetLineWidth(w)
    26  		dc.DrawLine(x1, y1, x2, y2)
    27  		dc.Stroke()
    28  	}
    29  	dc.SavePNG("out.png")
    30  }
    31  
    32  func TestText(t *testing.T) {
    33  	const S = 100
    34  	dc := NewContext(S, S)
    35  	dc.SetRGB(1, 1, 1)
    36  	dc.Clear()
    37  	dc.SetRGB(0, 0, 0)
    38  	dc.DrawStringAnchored("abcd1234", S/2, S/2, 0.5, 0.5)
    39  	dc.SavePNG("out.png")
    40  }