-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannulus.go
150 lines (123 loc) · 3.23 KB
/
annulus.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package goannular
import (
"fmt"
"math"
"math/rand"
"strconv"
"strings"
)
type Annulus struct {
x, y, start, end, inner, outer float64
}
func (a Annulus) moveTo() string {
x := a.x + a.outer*math.Cos(a.start)
y := a.y + a.outer*math.Sin(a.start)
mt := fmt.Sprintf(
"M%s,%s ",
strconv.FormatFloat(x, 'f', -1, 64),
strconv.FormatFloat(y, 'f', -1, 64),
)
return (mt)
}
func (a Annulus) ellipticalArcCurve(inorout string) string {
var angle, sweepflag int
var rx, ry, x, y float64
arcLength := a.end - a.start
arc := math.Mod(arcLength, 2*math.Pi)
largeArc := 0
if arc > math.Pi {
largeArc = 1
}
switch inorout {
case "outer":
angle = 0
sweepflag = 1
rx = a.outer
ry = a.outer
x = a.x + a.outer*math.Cos(a.end)
y = a.y + a.outer*math.Sin(a.end)
case "inner":
angle = 0
sweepflag = 0
rx = a.inner
ry = a.inner
x = a.x + a.inner*math.Cos(a.start)
y = a.y + a.inner*math.Sin(a.start)
}
eac := fmt.Sprintf(
"A%s,%s,%s,%s,%s,%s,%s ",
strconv.FormatFloat(rx, 'f', -1, 64),
strconv.FormatFloat(ry, 'f', -1, 64),
strconv.Itoa(angle),
strconv.Itoa(largeArc),
strconv.Itoa(sweepflag),
strconv.FormatFloat(x, 'f', -1, 64),
strconv.FormatFloat(y, 'f', -1, 64),
)
return (eac)
}
func (a Annulus) lineTo() string {
x := a.x + a.inner*math.Cos(a.end)
y := a.y + a.inner*math.Sin(a.end)
lt := fmt.Sprintf(
"L%s,%s ",
strconv.FormatFloat(x, 'f', -1, 64),
strconv.FormatFloat(y, 'f', -1, 64),
)
return (lt)
}
func (a Annulus) SVG() string {
var d strings.Builder
d.WriteString(a.moveTo())
d.WriteString(a.ellipticalArcCurve("outer"))
d.WriteString(a.lineTo())
d.WriteString(a.ellipticalArcCurve("inner"))
d.WriteString("z")
return d.String()
}
func radialLength(radialStart, maxRadialLength, arcStart float64, stype int) float64 {
adjRadiusLimits := []float64{250.0, 500.0}
var radialLength float64
switch stype {
case 0: // starburst
radialLength = rand.Float64() * maxRadialLength //px
case 1: // ???
switch {
case radialStart < adjRadiusLimits[0]:
radialLength = rand.Float64() * maxRadialLength / 3.0 //px
case radialStart >= adjRadiusLimits[0] && radialStart < adjRadiusLimits[1]:
radialLength = rand.Float64() * maxRadialLength / 2.0 //px
case radialStart >= adjRadiusLimits[1]:
radialLength = rand.Float64() * maxRadialLength / 1.0 //px
}
case 2:
radialLength = rand.Float64() * maxRadialLength
case 3:
maxRadialLength = rand.Float64() * maxRadialLength
radialLength = rand.Float64() * maxRadialLength
}
return radialLength
}
func arcLength(arcStart, maxArcLength, radialStart float64, stype int) float64 {
adjRadiusLimits := []float64{250.0, 500.0}
var arcLength float64
switch stype {
case 0:
arcLength = rand.Float64() * 1.0 //px
case 1:
switch {
case radialStart < adjRadiusLimits[0]:
arcLength = rand.Float64() * maxArcLength / 3.0 //px
case radialStart >= adjRadiusLimits[0] && radialStart < adjRadiusLimits[1]:
arcLength = rand.Float64() * maxArcLength / 2.0 //px
case radialStart >= adjRadiusLimits[1]:
arcLength = rand.Float64() * maxArcLength / 1.0 //px
}
case 2:
arcLength = rand.Float64() * maxArcLength
case 3:
maxArcLength = rand.Float64() * maxArcLength
arcLength = rand.Float64() * maxArcLength
}
return arcLength
}