Tw1ddle / geometrize-haxe

:triangular_ruler: Geometrize is a Haxe port of primitive that geometrizes images into geometric primitives
https://www.geometrize.co.uk/
Other
348 stars 31 forks source link

randomly move existing shapes #12

Closed mastef closed 5 years ago

mastef commented 6 years ago

The algo could also try moving existing shapes randomly a few pixels left and right. Would make for a nice effect

Tw1ddle commented 6 years ago

Hi, do you just mean do a little animation or actually change the main algorithm to shift existing shapes around? At the moment shapes are added one by one there's no global optimization.

I'd say animations are better suited as transformations to exported shape data. These are a bit rough but there are some examples of that. First one might kill your computer.

https://tweens.geometrize.co.uk/ http://tweenoptimizer.geometrize.co.uk/ https://twitter.com/JoeCreates/status/927623110962053123

mastef commented 6 years ago

Hey, actually I meant shifting existing shapes around as part of the step process - as other positions might be better suited. It might also looks nicer as the painting progresses

Tw1ddle commented 6 years ago

I would find optimal solutions using a library like nlopt to do that. The current algorithm hillclimbs to add one shape at a time and isn't suited for looking back and improving previous shapes.

Making the progression look nicer visually is best as a postprocessing option. It would be possible to do that "live" if you added shapes being produced by the library to an animated SVG for example.

cancerberoSgx commented 5 years ago

I take advantage of this issue to ask something that seems related.

In shape's mutate methods I see fixed numbers to move / rotate randomly https://github.com/Tw1ddle/geometrize-haxe/blob/f002c86c01cdc80373ed7437741175301fd2c219/geometrize/shape/RotatedEllipse.hx#L58

The values are consistent between all shapes (16 for translation, 4 for angles, and I think I also saw a 32 but no more. If I'n not missing something important I think those can be changed safely right @Tw1ddle . And make them configurable could add some value to users ? I will try to test how the result change,

Also, for bounds, wouldn't be better that instead of fixed values they are are proportional with image height/width ? Perhaps I'm totally wrong, or this will break some aesthetics I don't understand ?

Thanks

Tw1ddle commented 5 years ago

What was being asked here is a little different: for the algorithm to randomly move already-added shapes. I'd rather leave that to another project using a different algorithm or as a postprocessing effect as I mentioned (so closing this issue).

To answer your question, the values used for the shape setup and mutation could certainly be pulled out and made configurable. Customizing would change the final results, depends on the image used.

In my desktop C++/Qt application I made those functions rebindable, and then added additional versions of these as Chaiscript scripts e.g: https://github.com/Tw1ddle/geometrize-scripts/blob/783e5c670d0aca2394d9a81308c7b77fa4fe39db/scripts/default_shape_mutators/mutateCircle.chai - something similar would also be possible using HxScript (https://github.com/HaxeFoundation/hscript), I expect this would run a lot slower than the C++/Chaiscript implementation though.