I am trying to generate a Spierpinki Triangle in Python using the Chaos game. The computations of the points to plot seem correct however, instead of thousands of points plotted, only 10 or so are plotted.
import math
import numpy as np
import random as rand
import matplotlib.pyplot as plt
# Defining vertices
t = np.linspace(0, (2 * math.pi), 4)
v = np.array([[math.cos(t[0]), math.cos(t[1]), math.cos(t[2])],
[math.sin(t[0]), math.sin(t[1]), math.sin(t[2])]])
# Defining Starting point
T = np.array([[0.5, 0], [0, 0.5]])
x = np.array([rand.random() - 0.5, rand.random() - 0.5]).reshape(2, 1)
res = np.zeros((2, 1))
n = 10000
for i in range(n):
for j in range(2):
k = rand.randint(0, 2)
res = np.expand_dims(res, axis=0)
res = np.multiply(T, np.subtract(x[j], v[:, k])) + v[:, k]
xx = [x for (x, y) in res]
yy = [y for (x, y) in res]
plt.plot(xx, yy, 'b.')
plt.show()