Skip to content

Commit 89883fa

Browse files
committed
test and draw examples
1 parent 29ae55d commit 89883fa

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

drawPNG/main.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"math/rand"
5+
"time"
6+
"fmt"
7+
"github.com/fogleman/gg"
8+
)
9+
10+
11+
func main() {
12+
r := rand.New(rand.NewSource(99))
13+
r.Seed(time.Now().UTC().UnixNano())
14+
15+
drawItem:= gg.NewContext(1000,1000)
16+
17+
18+
drawItem.SetHexColor("#fff")
19+
drawItem.DrawRectangle(0,0,1000,1000)
20+
drawItem.Fill()
21+
for i := 0; i < 40; i++ {
22+
for j := 0; j < 40; j++ {
23+
randColor:=r.Intn(16000000)
24+
randSize:=r.Intn(25)
25+
randomHex:=fmt.Sprintf("#%.6X", randColor)
26+
fmt.Println(randomHex)
27+
drawItem.SetHexColor(randomHex)
28+
drawItem.DrawCircle(float64(i*30),float64(j*30),float64(randSize))
29+
drawItem.Fill()
30+
31+
}
32+
}
33+
34+
defer drawItem.SavePNG("out3.png")
35+
36+
}

drawPNG/out3.png

394 KB
Loading

testExample/test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import "testing"
4+
5+
func TestSum(t *testing.T) {
6+
var total = sum(5, 5)
7+
if total != 10 {
8+
t.Errorf("Sum was incorrect, got: %d, want: %d.", total, 10)
9+
}
10+
}
11+
12+
13+
func sum(x int, y int) int {
14+
return x + y
15+
}

testExample/testmain.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func sum(x int, y int) int {
8+
return x + y
9+
}
10+
11+
func main() {
12+
var c = sum(5, 5)
13+
fmt.Println(c)
14+
}

0 commit comments

Comments
 (0)