MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / chaosGame

Function chaosGame

contents/IFS/code/cpp/IFS.cpp:40–52  ·  view source on GitHub ↗

This is a function to simulate a "chaos game"

Source from the content-addressed store, hash-verified

38
39// This is a function to simulate a "chaos game"
40PointVector 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
54int main() {
55 // This will generate a Sierpinski triangle with a chaos game of n points for

Callers 1

mainFunction · 0.85

Calls 2

chooseFunction · 0.85
drandFunction · 0.70

Tested by

no test coverage detected