Code optimisation by subpixel to allow faster drawing for realtime animation, animating the last fold over time and interactive with mouse movement.
Based on the fabulous Origami Butterfly by Kyle McDonald.
Keys:
[space] to pause
[1]-[5] to switch the source image (with the same folding),
[f] to create a new folding (with a random number of folds),
[e] to display extra information: the folded paper and points used to animate the last fold.
A modification of the Origami Butterfly Method by Jonathan McCabe. The original algorithm can be paraphrased:
- Fold a piece of paper (a few times)
- Note the new position of each point on the paper
- Unfold the paper
- For each point, use the noted (folded) position to determine that point's color
The primary modification is the last step: instead of a point in color space, the positions represent a sample from an image space - painting some unexpected organic patterns, and leading to a simpler metaphor for the algorithm:
- Fold a piece of paper (a few times)
- Project an image onto the paper (like tie-dye)
- Unfold the paper
Performance metrics compared to original code (470x353, 32 folds). Note: these times are merely quickest times observed from debug output and are cumulative in the order presented.
- Original time: ~460ms
- Replace folds[][2][2] with foldsx0, foldsy0, foldsx1, foldsy1: 420ms (-41ms)
- Replace closest[2] with closestx, closesty: 351ms (-69ms)
- Inline refelct(): 220ms (-131ms)
- Replace foldedImage[][][] with foldedImagex[], foldedImage[y]: 150ms (-70ms)
An approximately 3x speed improvement overall, allowing for rendering as a realtime animation, especially with fewer folds.
Source code: spxlOrigamiButterfly
Built with Processing