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
|
// Command ff-primitive takes farbfeld data from standard in and applies http://primitive.lol to it.
package main
import (
"flag"
"image"
"log"
"os"
"runtime"
"runtime/pprof"
"github.com/fogleman/primitive/primitive"
farbfeld "github.com/hullerob/go.farbfeld"
"within.website/x/internal"
)
var (
shapeCount = flag.Int("count", 150, "number of shapes used")
repeatShapeCount = flag.Int("repeat-count", 0, "number of extra shapes drawn in each step")
alpha = flag.Int("alpha", 128, "alpha of all shapes")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
)
func stepImg(img image.Image, count int) image.Image {
bg := primitive.MakeColor(primitive.AverageImageColor(img))
model := primitive.NewModel(img, bg, 512, runtime.NumCPU())
for range make([]struct{}, count) {
model.Step(primitive.ShapeTypeTriangle, *alpha, *repeatShapeCount)
}
return model.Context.Image()
}
func main() {
internal.HandleStartup()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
img, err := farbfeld.Decode(os.Stdin)
if err != nil {
log.Fatal(err)
}
err = farbfeld.Encode(os.Stdout, stepImg(img, *shapeCount))
if err != nil {
log.Fatal(err)
}
}
|