Pyplot how to plot math art
Take the first example in the reported link:
So you have to do a for loop with k
from 1 to N = 14000
, in each iteration you draw a circle of radius R
and center in (X, Y)
defined in the above equations:
N = 14000
for k in range(1, N + 1):
X = cos(10*pi*k/N)*(1 - 1/2*(cos(16*pi*k/N))**2)
Y = sin(10*pi*k/N)*(1 - 1/2*(cos(16*pi*k/N))**2)
R = 1/200 + 1/10*(sin(52*pi*k/N))**4
At this point you have the coordinates of the circle's center and its radius, but not the circle iteself yet, so you you have to compute it. First of all you have to define an angle theta
from 0
to 2*pi
, then compute the cirle's points with:
N = 14000
theta = np.linspace(0, 2*pi, 361)
for k in range(1, N + 1):
X = cos(10*pi*k/N)*(1 - 1/2*(cos(16*pi*k/N))**2)
Y = sin(10*pi*k/N)*(1 - 1/2*(cos(16*pi*k/N))**2)
R = 1/200 + 1/10*(sin(52*pi*k/N))**4
x = R*np.cos(theta) + X
y = R*np.sin(theta) + Y
Finally, you can draw the circles in each iteration.
Complete code
import numpy as np
import matplotlib.pyplot as plt
from math import sin, cos, pi
N = 14000
theta = np.linspace(0, 2*pi, 361)
fig, ax = plt.subplots(figsize = (10, 10))
for k in range(1, N + 1):
X = cos(10*pi*k/N)*(1 - 1/2*(cos(16*pi*k/N))**2)
Y = sin(10*pi*k/N)*(1 - 1/2*(cos(16*pi*k/N))**2)
R = 1/200 + 1/10*(sin(52*pi*k/N))**4
x = R*np.cos(theta) + X
y = R*np.sin(theta) + Y
ax.plot(x, y, color = 'blue', linewidth = 0.1)
plt.show()