Modulo Multiplication Patterns using Python
This article is inspired from a YouTube video by Mathologer that explains the mathematics behind vortex mathematics and Tesla's 3-6-9 pattern. Please refer the video to understand the logic behind these patterns.
The Python code to generate (at the end) Modulo Multiplication patterns take two inputs, Modulus and Multiplier. Here are some examples with different values of input.
Modulus - 500, Multiplier - 2
Multiplier 2 generate the famous cardioid curve. A cardioid is generated by tracing a point on a circle rolling on another circle of the same radius. To read more about cardioid refer to this article.
Modulus - 7417, Multiplier - 240
Some more patterns (ModulusxMultiplier):
5400x201 5460x305 8456x266
Generate Modulus Multiplication patterns in Python 3
import matplotlib.pyplot as plt
import numpy as np
import warnings
warnings.filterwarnings("ignore")
Modulus = int(input('Enter Modulus'))
Multiplier = int(input('Enter Multiplier'))
# Define Line Width based on modulus
if Modulus < 20:
l = 2
elif (Modulus >= 20) and (Modulus < 1000):
l = 1
elif (Modulus >= 1000) and (Modulus < 3000):
l = 0.5
elif (Modulus >= 3000) and (Modulus < 5000):
l = 0.1
elif (Modulus >= 3000) and (Modulus < 10000):
l = 0.05
else:
l = 0.01
## Initiate the plot
figure, ax = plt.subplots(figsize=(12, 12))
# Hide the axis spines
plt.style.use('dark_background') ax.axis('off')
theta = np.linspace(0, 2 * np.pi, 180)
### Plot a circle
radius = 0.5
a = radius * np.cos(theta)
b = radius * np.sin(theta)
ax.plot(a, b, color='m')
## Plot markers on the circle equal to Modulus
c = np.arange(Modulus)
d = np.pi / 2 + (2 * np.pi * c) / Modulus ## Start wih pi/2 so we have 9 at the top
x = radius * np.cos(d)
y = radius * np.sin(d)
ax.scatter(x, y, color='m', s=0.5)
## Plot the lines
k = np.arange(1, Modulus + 1)
r = 0
a = []
aa = np.array([])
for i in k:
if r in aa:
pass
else:
r = i
a = [i]
for j in range(1, Modulus + 1):
r = (r * Multiplier) % Modulus
if (r in a) or (r in aa):
break
a.append(r)
a.append(r)
k = np.array(a)
aa = np.concatenate((aa, k))
# print(a)
k = np.array(a)
g = np.pi / 2 + (2 * np.pi * k) / Modulus
r = radius * np.cos(g)
s = radius * np.sin(g)
plt.plot(r, s, color='m', linewidth=l)
## Plot settings
ax.set_aspect(1)
#plt.title('Modular Multiplication')
plt.show()
Provide integer values for Modulus and Multiplier to generate the vortex curves.
Comments
Post a Comment