1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| func Test_line(t *testing.T) { img := image.NewRGBA(image.Rect(0, 0, _WIDTH, _HIGH))
cs := []color.RGBA{ {255, 0, 0, 255}, {255, 255, 0, 255}, {0, 255, 0, 255}, {0, 255, 255, 255}, {0, 0, 255, 255}, {255, 0, 255, 255}, } x0 := _WIDTH / 2 y0 := _HIGH / 2 cs_i := 0 for i := 0; i < _WIDTH; i += 7 { x := i y := 0 cs_i++ line(img, x, y, x0, y0, cs[cs_i%len(cs)]) } for i := 0; i < _HIGH; i += 8 { x := _WIDTH y := i cs_i++ line(img, x, y, x0, y0, cs[cs_i%len(cs)]) } for i := _WIDTH; i >= 0; i -= 10 { x := i y := _HIGH cs_i++ line(img, x, y, x0, y0, cs[cs_i%len(cs)]) } for i := _HIGH; i >= 0; i -= 10 { x := 0 y := i cs_i++ line(img, x, y, x0, y0, cs[cs_i%len(cs)]) }
f, _ := os.OpenFile("line.png", os.O_WRONLY|os.O_CREATE, 0600) defer f.Close() png.Encode(f, img) }
|