Modular Designs With Python (Congruence Theory)
Modular Designs
Congruence theory can be used to generate beautiful designs. It is really a fun way to study congruences. Two such designs are created using python. $m$-pointed stars and $(m,n)$ residue designs.
$m$ - Pointed Stars
To construct an $m$-pointed star, mark $m$ equally spaced points on a large circle, and label them with the least residue 0 through $(m-1)$ modulo $m$. Choose a least residue $i$ modulo $m$, where ($i,m$) = 1. Join each point $x$ with the point $x + r$ modulo $m$. Now colour in the various regions inside the circle with some solid colours. We should get a nice $m$-pointed star.
A python program can be written to draw an $m$-pointed star, where the value of m and $r$ can be chosen by the user.
Program
import turtle
from math import *
m = int(input("Enter the value of m: "))
r = int(input("Enter the value of r: "))
t = turtle.Turtle()
t.speed(3)
t.penup()
t.color("black","cyan")
t.setposition(0,-100)
t.pendown()
a=[]
for i in range(m):
t.circle(100,360/m)
t.dot(5,"blue")
s = t.position()
t.write(i)
a.append(s)
n = len(a)
t.penup()
t.setposition(a[0])
t.pendown()
i = 0
t.begin_fill()
while i <= m*r:
t.setposition(a[i%m])
i+=r
t.end_fill()
Output
$(m,n)$ Residue Designs
To construct an $(m,n)$ residue design, where $1 \leq n < m$ and $(m,n) = 1$, select $m-1$ equally spaced points on a large circle. Label them 1 through $m -1$, and join each $x$ to point $nx$ modulo $m$. Then color in the various regions formed in a systematic way to create exciting designs.
The python program to do the same is given below. The program asks the user to input the values of $m$ and $n$.
Program
import turtle
m = int(input("Enter the value of m: "))
n = int(input("Enter the value of n: "))
t = turtle.Turtle()
t.speed(3)
t.color("black","cyan")
a = []
for i in range(1,m):
t.circle(100,360/(m-1))
t.dot(5,"blue")
t.write(i)
a.append(t.position())
t.penup()
t.setposition(a[0])
t.pendown()
a.append((0,0))
i = 0
t.begin_fill()
while i < m-1:
t.goto(a[(((i+1)*n)%m)-1])
t.penup()
i += 1
t.goto(a[i])
t.pendown()
t.end_fill()
0 comments:
Post a Comment