-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurplecrayon_test.go
42 lines (36 loc) · 1.4 KB
/
purplecrayon_test.go
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
package purplecrayon_test
import (
pc "github.com/jordan-bonecutter/purplecrayon"
_ "github.com/jordan-bonecutter/purplecrayon/svg"
"log"
"os"
)
func Example() {
canv, err := pc.NewCanvas("svg", 1920, 1080, os.Stdout)
if err != nil {
log.Fatalf("Failed opening canvas: %s\n", err)
}
defer canv.Close()
rect := canv.Rect()
rect.Width(100).Height(100).TopLeft(pc.Point{X: 400, Y: 500})
rect.FillRGB(pc.RGB{R: 255, G: 0, B: 0})
rect.Close()
gradient := canv.LinearGradient()
gradient.SetLine(pc.Point{X: 0, Y: 0}, pc.Point{X: 1, Y: 1})
stops := gradient.GradientStops()
stops.Stop().Position(0.1).RGBA(pc.RGBA{R: 255, G: 120, B: 0, A: 127}).Finish()
stops.Stop().Position(0.9).RGBA(pc.RGBA{R: 255, G: 0, B: 120, A: 255}).Finish()
stops.Finish()
ref := gradient.Close()
circle := canv.Circle().Center(pc.Point{X: 1920 / 2, Y: 1080 / 2}).Radius(400)
circle.Fill(ref)
circle.Close()
// Output:
// <svg id="pcobj-0" width="1920" height="1080" xmlns="http://www.w3.org/2000/svg">
// <!-- Generated by purplecrayon -->
// <rect id="pcobj-1" width="100" height="100" x="400" y="500" fill="rgb(255,0,0)"/>
// <linearGradient id="pcobj-2" x1="0" y1="0" x2="1" y2="1">
// <stop id="pcobj-3" offset="10%" stop-color="rgba(255,120,0,127)"/>
// <stop id="pcobj-4" offset="90%" stop-color="rgba(255,0,120,255)"/></linearGradient>
// <circle id="pcobj-5" cx="960" cy="540" r="400" fill="url(#pcobj-2)"/></svg>
}