2828 Mode int
2929 Workers int
3030 Max float64
31+ Maxpct float64
3132 rfs float64
3233 Nth int
3334 Repeat int
@@ -71,11 +72,12 @@ func init() {
7172 flag .Var (& Configs , "n" , "number of primitives" )
7273 flag .StringVar (& Background , "bg" , "" , "background color (hex)" )
7374 flag .IntVar (& Alpha , "a" , 128 , "alpha value" )
74- flag .IntVar (& InputSize , "r" , 256 , "resize large input images to this size" )
75+ flag .IntVar (& InputSize , "r" , 256 , "resize large input images to this size only if larger than specified " )
7576 flag .IntVar (& OutputSize , "s" , 1024 , "output image size" )
7677 flag .IntVar (& Mode , "m" , 1 , "0=combo 1=triangle 2=rect 3=ellipse 4=circle 5=rotatedrect 6=beziers 7=rotatedellipse 8=polygon" )
7778 flag .IntVar (& Workers , "j" , 0 , "number of parallel workers (default uses all cores)" )
7879 flag .Float64Var (& Max , "ma" , 0 , "target score to stop adding primitives (default 0)" )
80+ flag .Float64Var (& Maxpct , "mp" , 0 , "target score in % to stop adding primitives (default 100)" )
7981 flag .IntVar (& Nth , "nth" , 1 , "save every Nth frame (put \" %d\" in path)" )
8082 flag .IntVar (& Repeat , "rep" , 0 , "add N extra shapes per iteration with reduced search" )
8183 flag .BoolVar (& V , "v" , false , "verbose" )
@@ -158,9 +160,13 @@ func main() {
158160 }
159161
160162 // run algorithm
163+ var startScore float64
164+
161165 model := primitive .NewModel (input , bg , OutputSize , Workers )
162166 primitive .Log (1 , "%d: t=%.3f, score=%.6f\n " , 0 , 0.0 , model .Score )
163167
168+ startScore = model .Score
169+
164170 start := time .Now ()
165171 frame := 0
166172 for j , config := range Configs {
@@ -176,7 +182,10 @@ func main() {
176182 nps := primitive .NumberString (float64 (n ) / time .Since (t ).Seconds ())
177183 elapsed := time .Since (start ).Seconds ()
178184
179- primitive .Log (1 , "%d: t=%.3f, score=%.6f, n=%d, n/s=%s\n " , frame , elapsed , model .Score , n , nps )
185+ var pctScore float64
186+ pctScore = 100 - (model .Score / startScore * 100 )
187+
188+ primitive .Log (1 , "%d: t=%.3f, score=%.6f, n=%d, n/s=%s, percent score=%.3f%%\n " , frame , elapsed , model .Score , n , nps , pctScore )
180189
181190 // write output image(s)
182191 for _ , output := range Outputs {
@@ -185,7 +194,7 @@ func main() {
185194 saveFrames := percent && ext != ".gif"
186195 saveFrames = saveFrames && frame % Nth == 0
187196 last := j == len (Configs )- 1 && i == config .Count - 1
188- if saveFrames || last || model .Score <= Max {
197+ if saveFrames || last || model .Score <= Max || pctScore >= Maxpct {
189198 path := output
190199 if percent {
191200 path = fmt .Sprintf (output , frame )
@@ -204,7 +213,7 @@ func main() {
204213 frames := model .Frames (0.001 )
205214 check (primitive .SaveGIFImageMagick (path , frames , 50 , 250 ))
206215 }
207- if model .Score <= Max {
216+ if model .Score <= Max || pctScore >= Maxpct {
208217 return
209218 }
210219 }
0 commit comments