-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvoronoi_circle.go
111 lines (92 loc) · 1.76 KB
/
voronoi_circle.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
package main
import (
. "github.com/buchanae/ink/color"
"github.com/buchanae/ink/dd"
. "github.com/buchanae/ink/dd"
"github.com/buchanae/ink/gfx"
"github.com/buchanae/ink/math"
"github.com/buchanae/ink/rand"
"github.com/buchanae/ink/voronoi"
)
func Ink(doc gfx.Doc) {
rand.SeedNow()
col := rand.Color(rand.Palette())
c := dd.Circle{
XY: gfx.Center,
Radius: .5,
Segments: 10,
}
m := doc.NewLayer()
gfx.Clear(m, RGBA{0, 0, 0, 1})
gfx.Fill{
Shape: c,
Color: RGBA{1, 0, 0, 1},
}.Draw(m)
vc := VoronoiCells{
Rect: gfx.Fullscreen,
Spacing: math.Interp(0.001, 0.01, .9),
}
s := doc.NewLayer()
gfx.Clear(s, RGBA{1, 1, 1, 1})
gfx.Fill{
Shape: vc.Mesh(),
Color: col,
}.Draw(s)
N := 17
for i := 0; i < 15; i++ {
y := .2 + float32(i)/15 + rand.Range(-.01, .01)
l := NewLine(XY{0, y}, XY{1, y})
sub := Subdivide(l, N)
for i, _ := range sub {
dy := rand.Range(-.1, .1)
sub[i].Y += dy
}
modified := XYsToLines(sub...)
path := Path{}
for _, line := range modified {
path = append(path, line)
}
gfx.Stroke{
Shape: path,
Width: .01,
Color: RGBA{0, 0, 0, 1},
}.Draw(m)
gfx.Stroke{
Shape: path,
Width: -.002,
Color: col,
}.Draw(s)
gfx.Stroke{
Shape: path,
Width: .022,
Color: col,
}.Draw(s)
}
gfx.Stroke{
Shape: c,
Width: .003,
Color: col,
}.Draw(s)
gfx.Mask{
Rect: gfx.Fullscreen,
Source: s,
Mask: m,
}.Draw(doc)
}
type VoronoiCells struct {
Rect
Spacing float32
}
func (vc VoronoiCells) Mesh() Mesh {
bn := rand.BlueNoise{
Rect: vc.Rect,
Spacing: vc.Spacing,
}
noise := bn.Generate()
v := voronoi.New(noise, vc.Rect)
var meshes []Mesh
for _, e := range v.Edges() {
meshes = append(meshes, e.Stroke(StrokeOpt{}))
}
return Merge(meshes...)
}