This is a function to simulate a "chaos game"
| 38 | |
| 39 | // This is a function to simulate a "chaos game" |
| 40 | PointVector chaosGame(int numOutputPoints, const PointVector& inputPoints) { |
| 41 | // Choose first point randomly |
| 42 | Point curPoint = {drand(), drand()}; |
| 43 | |
| 44 | // For each output point, compute midpoint to random input point |
| 45 | PointVector outputPoints(numOutputPoints); |
| 46 | for (auto& outPoint : outputPoints) { |
| 47 | outPoint = curPoint; |
| 48 | curPoint = 0.5 * (curPoint + choose(inputPoints)); |
| 49 | } |
| 50 | |
| 51 | return outputPoints; |
| 52 | } |
| 53 | |
| 54 | int main() { |
| 55 | // This will generate a Sierpinski triangle with a chaos game of n points for |