speice.io/blog/2024-11-15-playing-with-fire/1-introduction/Gasket.jsx

25 lines
604 B
React
Raw Normal View History

2024-11-17 20:42:42 -05:00
// Hint: try increasing the iteration count
const iterations = 10000;
2024-11-17 20:42:42 -05:00
// Hint: negating `x` and `y` also creates some interesting images
const functions = [
(x, y) => [x / 2, y / 2],
(x, y) => [(x + 1) / 2, y / 2],
(x, y) => [x / 2, (y + 1) / 2]
]
2024-11-17 20:42:42 -05:00
function chaosGame(image) {
var [x, y] = [randomBiUnit(), randomBiUnit()];
2024-11-17 20:42:42 -05:00
for (var count = 0; count < iterations; count++) {
const i = randomInteger(0, functions.length);
[x, y] = functions[i](x, y);
2024-11-17 20:42:42 -05:00
if (count > 20) {
plot(x, y, image);
}
}
}
2024-11-17 20:42:42 -05:00
render(<Canvas renderFn={chaosGame}/>)