fogleman / primitive

Reproducing images with geometric primitives.
https://primitive.lol/
MIT License
12.35k stars 608 forks source link

Inconsistent -rep parsing withmultiple configs #57

Open davethegr8 opened 6 years ago

davethegr8 commented 6 years ago

Apparently it's possible to pass multiple -m {mode} -n {num} configs, which is really cool. However, when I was trying it, I noticed that some -rep settings were not being used (or it wasn't using the right ones).

This is the command I'm using:

> GOPATH=/Users/davethegr8/Dropbox/primitives time go run src/github.com/fogleman/primitive/main.go -v -i flower.jpg -o "flower/20171017145645-m0-n1-rep1-m1-n1-rep2-m5-n1-rep2-m6-n1-rep2.svg" -m 0 -n 1 -rep 1 -m 1 -n 1 -rep 2 -m 5 -n 1 -rep 2 -m 6 -n 1 -rep 2

And here's output:

0 <== I hacked in fmt.Println(Repeat) in func (i *shapeConfigArray) Set(value string)
1
2
2
2
{1 0 128 0} <== added fmt.Println(config) in for _, config := range Configs
{1 1 128 1}
{1 5 128 2}
{1 6 128 2}
reading flower.jpg
0: t=0.000, score=0.222857
count=1, mode=0, alpha=128, repeat=0
1: t=0.626, score=0.165856, n=21553, n/s=34.4k
count=1, mode=1, alpha=128, repeat=1
0 1 <== added fmt.Println(i, repeat) in model.go line 124
2: t=1.377, score=0.114709, n=19751, n/s=26.3k
count=1, mode=5, alpha=128, repeat=2
0 2
1 2
3: t=1.515, score=0.103102, n=18435, n/s=133.5k
count=1, mode=6, alpha=128, repeat=2
0 2
1 2
4: t=1.664, score=0.102205, n=18285, n/s=122.8k
writing flower/20171017145645-m0-n1-rep1-m1-n1-rep2-m5-n1-rep2-m6-n1-rep2.svg

real    0m2.363s
user    0m9.185s
sys 0m0.188s

You can see that while I'm passing 4 -rep values, 5 are printed out, and when the shapeConfig objects are built, they are off by 1 with the default value getting stuck on the beginning.

I tried to see if I could fix the issue, but I'm not familiar enough with go.

tonykwok commented 6 years ago

Try the following command:

primitive -i flower.png -o result.svg -rep 1 -m 0 -n 1 -rep 2 -m 1 -n 1 -rep 2 -m 5 -n 1 -rep 2 -m 6 -n 1

that's to say, you MUST specify the arguments in this order: -rep then -m and finally -n :)

davethegr8 commented 6 years ago

Ah, interesting. That does produce the intended effect, though it's not clear to me why...

Thanks!