forked from jdxyw/generativeart
/
noiseline.go
64 lines (55 loc) · 1.41 KB
/
noiseline.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
package arts
import (
"math"
"math/rand"
"github.com/andrewwatson/generativeart"
"github.com/andrewwatson/generativeart/common"
"github.com/fogleman/gg"
)
type noiseLine struct {
n int
elipses bool
}
// NewNoiseLine returns a noiseLine object.
func NewNoiseLine(n int, elipses bool) *noiseLine {
return &noiseLine{
n: n,
elipses: elipses,
}
}
// Generative draws a noise line image.
func (nl *noiseLine) Generative(c *generativeart.Canva) string {
ctex := gg.NewContextForRGBA(c.Img())
noise := common.NewPerlinNoise()
ctex.SetColor(common.Black)
if nl.elipses {
for i := 0; i < 80; i++ {
x := rand.Float64() * float64(c.Width())
y := rand.Float64() * float64(c.Height())
s := rand.Float64() * float64(c.Width()) / 8
ctex.SetLineWidth(0.5)
ctex.DrawEllipse(x, y, s, s)
ctex.Stroke()
}
}
t := rand.Float64() * 10
for i := 0; i < nl.n; i++ {
x := common.RandomRangeFloat64(-0.5, 1.5) * float64(c.Width())
y := common.RandomRangeFloat64(-0.5, 1.5) * float64(c.Height())
cl := c.Opts().ColorSchema()[rand.Intn(len(c.Opts().ColorSchema()))]
cl.A = uint8(c.Opts().Alpha())
l := 400
for j := 0; j < l; j++ {
var ns = 0.0005
w := math.Sin(math.Pi*float64(j)/float64(l-1)) * 5
theta := noise.Noise3D(x*ns, y*ns, t) * 100
ctex.SetColor(cl)
ctex.DrawCircle(x, y, w)
ctex.Fill()
x += math.Cos(theta)
y += math.Sin(theta)
t += 0.0000003
}
}
return ""
}