-
Notifications
You must be signed in to change notification settings - Fork 5
/
aurora.go
269 lines (259 loc) · 8.4 KB
/
aurora.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package aurora
import (
"log"
"os"
"github.com/ajstarks/svgo"
)
var (
svgFile *os.File
err error
)
//Color : var created so that user can access svg.Offcolor
type Color svg.Offcolor
//Gradient : type for storing slices of Color
type Gradient struct {
Colors []Color
}
//Gradients : Pre-defined gradients.
var Gradients = []Gradient{
{[]Color{{0, "#fcdf8a", 1.0}, {100, "#F38381", 1.0}}},
{[]Color{{0, "#f54ea2", 1.0}, {100, "#FF7676", 1.0}}},
{[]Color{{0, "#17ead9", 1.0}, {100, "#6078EA", 1.0}}},
{[]Color{{0, "#622774", 1.0}, {100, "#C53364", 1.0}}},
{[]Color{{0, "#7117ea", 1.0}, {100, "#EA6060", 1.0}}},
{[]Color{{0, "#42e695", 1.0}, {100, "#3BB2B8", 1.0}}},
{[]Color{{0, "#f02fc2", 1.0}, {100, "#6094ea", 1.0}}},
{[]Color{{0, "#65799b", 1.0}, {100, "#5e2563", 1.0}}},
{[]Color{{0, "#184e68", 1.0}, {100, "#57ca85", 1.0}}},
{[]Color{{0, "#5b247a", 1.0}, {100, "#1bcedf", 1.0}}},
{[]Color{{0, "#fad961", 1.0}, {100, "#f76b1c", 1.0}}},
{[]Color{{0, "#f2d50f", 1.0}, {100, "#da0641", 1.0}}},
{[]Color{{0, "#F5515F", 1.0}, {100, "#A1051D", 1.0}}},
{[]Color{{0, "#F36265", 1.0}, {100, "#961276", 1.0}}},
{[]Color{{0, "#FF57B9", 1.0}, {100, "#A704FD", 1.0}}},
{[]Color{{0, "#C56CD6", 1.0}, {100, "#3425AF", 1.0}}},
{[]Color{{0, "#13f1fc", 1.0}, {100, "#0470dc", 1.0}}},
{[]Color{{0, "#0FF0B3", 1.0}, {100, "#036ED9", 1.0}}},
{[]Color{{0, "#c3ec52", 1.0}, {100, "#0ba29d", 1.0}}},
{[]Color{{0, "#b1ea4d", 1.0}, {100, "#459522", 1.0}}},
{[]Color{{0, "#DFEC51", 1.0}, {100, "#73AA0A", 1.0}}},
{[]Color{{0, "#E3E3E3", 1.0}, {100, "#5D6874", 1.0}}},
{[]Color{{0, "#CE9FFC", 1.0}, {100, "#7367F0", 1.0}}},
}
/*CreateSquare generates square SVG image.
filename - filename without extension (eg:- "sherlock: for DrSeuss.svg)
quote - array of string to be made into quote (eg:-
["Don't cry because", "it's over,", "smile because", "it happened."])
author - author name (eg:- "Dr. Seuss")
*/
func CreateSquare(filename string, quote []string, author string, linearGrad []Color) {
// To convert Colors back to svg.Offcolor
var lg = []svg.Offcolor{}
for i := 0; i < len(linearGrad); i++ {
lg = append(lg, svg.Offcolor(linearGrad[i]))
}
// Adding Extension
filename += ".svg"
// Creating File
svgFile, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
// Adding Blockquotes to Quote Text
quote[0] = "\"" + quote[0]
quote[len(quote)-1] = quote[len(quote)-1] + "\""
// Finding Pixel Spacing
n := len(quote)
var qSpace int
//To make quote block vertically centered
if n%2 != 0 {
qSpace = int((float64(n) / float64(2))) * 75
} else {
qSpace = int((float64(n)/float64(2))-1) * 75
}
var aSpace int
//To make Author appear just below quote block vertically centered
if n%2 != 0 {
aSpace = int((float64(n)/float64(2))+1) * 75
} else {
aSpace = int((float64(n)/float64(2))+1) * 75
}
// aSpace := int(math.Max(float64((n-3)*150), 150))
aStyle := "text-anchor:middle;font-size:54px;fill:white;font-style:italic;"
// Height and Width
width := 1000
height := 1000
// Drawing Starts
canvas := svg.New(svgFile)
canvas.Start(width, height)
canvas.Def()
canvas.LinearGradient("bb", 0, 0, 100, 100, lg)
canvas.DefEnd()
canvas.Square(0, 0, 1000, "fill: url(#bb)")
canvas.Textlines(width/2, (height/2)-qSpace, quote, 72, 75, "white", "middle")
canvas.Text(width/2, (height/2)+aSpace, author, aStyle)
canvas.End()
svgFile.Close()
}
/*
CreateLand generates a landscape SVG image.
filename - filename without extension (eg:- "sherlock: for DrSeuss.svg)
quote - array of string to be made into quote (eg:-
["Don't cry because", "it's over,", "smile because", "it happened."])
author - author name (eg:- "Dr. Seuss")
*/
func CreateLand(filename string, quote []string, author string, linearGrad []Color) {
// To convert Colors back to svg.Offcolor
var lg = []svg.Offcolor{}
for i := 0; i < len(linearGrad); i++ {
lg = append(lg, svg.Offcolor(linearGrad[i]))
}
// Adding Extension
filename += ".svg"
// Creating File
svgFile, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
// Adding Blockquotes to Quote Text
quote[0] = "\"" + quote[0]
quote[len(quote)-1] = quote[len(quote)-1] + "\""
// Finding Pixel Spacing
n := len(quote)
//To make quote block vertically centered
var qSpace int
if n%2 != 0 {
qSpace = int((float64(n) / float64(2))) * 75
} else {
qSpace = int((float64(n)/float64(2))-1) * 75
}
var aSpace int
//To make Author appear just below quote block vertically centered
if n%2 != 0 {
aSpace = int((float64(n)/float64(2))+1) * 75
} else {
aSpace = int((float64(n)/float64(2) + 1)) * 75
}
aStyle := "text-anchor:middle;font-size:54px;fill:white;font-style:italic;"
// Height and Width
width := 1600
height := 1200
// Drawing Starts
canvas := svg.New(svgFile)
canvas.Start(width, height)
canvas.Def()
canvas.LinearGradient("bb", 0, 0, 100, 100, lg)
canvas.DefEnd()
canvas.Rect(0, 0, width, height, "fill: url(#bb)")
canvas.Textlines(width/2, (height/2)-qSpace, quote, 72, 75, "white", "middle")
canvas.Text(width/2, (height/2)+aSpace, author, aStyle)
canvas.End()
svgFile.Close()
}
/*
CreatePort generates a portrait SVG image.
filename - filename without extension (eg:- "sherlock: for DrSeuss.svg)
quote - array of string to be made into quote (eg:-
["Don't cry because", "it's over,", "smile because", "it happened."])
author - author name (eg:- "Dr. Seuss")
*/
func CreatePort(filename string, quote []string, author string, linearGrad []Color) {
// To convert Colors back to svg.Offcolor
var lg = []svg.Offcolor{}
for i := 0; i < len(linearGrad); i++ {
lg = append(lg, svg.Offcolor(linearGrad[i]))
}
// Adding Extension
filename += ".svg"
// Creating File
svgFile, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
// Adding Blockquotes to Quote Text
quote[0] = "\"" + quote[0]
quote[len(quote)-1] = quote[len(quote)-1] + "\""
// Finding Pixel Spacing
n := len(quote)
//To make quote block vertically centered
var qSpace int
if n%2 != 0 {
qSpace = int((float64(n) / float64(2))) * 75
} else {
qSpace = int((float64(n)/float64(2))-1) * 75
}
var aSpace int
//To make Author appear just below quote block vertically centered
if n%2 != 0 {
aSpace = int((float64(n)/float64(2))+1) * 75
} else {
aSpace = int((float64(n)/float64(2))+1) * 75
}
aStyle := "text-anchor:middle;font-size:54px;fill:white;font-style:italic;"
// Height and Width
width := 1200
height := 1600
// Drawing Starts
canvas := svg.New(svgFile)
canvas.Start(width, height)
canvas.Def()
canvas.LinearGradient("bb", 0, 0, 100, 100, lg)
canvas.DefEnd()
canvas.Rect(0, 0, width, height, "fill: url(#bb)")
canvas.Textlines(width/2, (height/2)-qSpace, quote, 72, 75, "white", "middle")
canvas.Text(width/2, (height/2)+aSpace, author, aStyle)
canvas.End()
svgFile.Close()
}
/*Create generates square SVG image of specific height and width.
filename - filename without extension (eg:- "sherlock: for DrSeuss.svg)
quote - array of string to be made into quote (eg:-
["Don't cry because", "it's over,", "smile because", "it happened."])
author - author name (eg:- "Dr. Seuss")
*/
func Create(filename string, quote []string, author string, height int, width int, linearGrad []Color) {
// To convert Colors back to svg.Offcolor
var lg = []svg.Offcolor{}
for i := 0; i < len(linearGrad); i++ {
lg = append(lg, svg.Offcolor(linearGrad[i]))
}
// Adding Extension
filename += ".svg"
// Creating File
svgFile, err := os.Create(filename)
if err != nil {
log.Fatal(err)
}
// Adding Blockquotes to Quote Text
quote[0] = "\"" + quote[0]
quote[len(quote)-1] = quote[len(quote)-1] + "\""
// Finding Pixel Spacing
n := len(quote)
var qSpace int
//To make quote block vertically centered
if n%2 != 0 {
qSpace = int((float64(n) / float64(2))) * 75
} else {
qSpace = int((float64(n)/float64(2))-1) * 75
}
var aSpace int
//To make Author appear just below quote block vertically centered
if n%2 != 0 {
aSpace = int((float64(n)/float64(2))+1) * 75
} else {
aSpace = int((float64(n)/float64(2))+1) * 75
}
// aSpace := int(math.Max(float64((n-3)*150), 150))
aStyle := "text-anchor:middle;font-size:54px;fill:white;font-style:italic;"
// Drawing Starts
canvas := svg.New(svgFile)
canvas.Start(width, height)
canvas.Def()
canvas.LinearGradient("bb", 0, 0, 100, 100, lg)
canvas.DefEnd()
canvas.Rect(0, 0, width, height, "fill: url(#bb)")
canvas.Textlines(width/2, (height/2)-qSpace, quote, 72, 75, "white", "middle")
canvas.Text(width/2, (height/2)+aSpace, author, aStyle)
canvas.End()
svgFile.Close()
}