I want to draw a modular multiplication circle using turtle library as showed in this link: https://yashaslokesh.github.io/mod-mult-circle.html
My questions are:
-
If the line already drawn, the turtle must not be passed by it again. So how to track the lines and how to do it?
-
If the multiplicator is decimal, how to make the problem work? Since I have seen an animation like this: https://www.youtube.com/watch?v=qhbuKbxJsk8 from 12min17s
Here is my code:
import turtle
import math
pen = turtle.Turtle()
pen.speed(0)
#num = nb of points on the circle
def Points(num, radius):
points = []
for i in range(num):
x = radius*math.cos(i*2*math.pi/num)
y = radius*math.sin(i*2*math.pi/num)
#coord = coordonnees des points
coord = (x,y)
points.append(coord)
return points
pointsList = Points(200, 250)
#points = list of the coordinates of points on the circle
def drawPoints(turtle, points):
turtle.up()
for i in range(len(points)):
coord = points[i]
turtle.goto(coord[0], coord[1])
turtle.dot(2.5)
def drawLines(turtle, points, mult):
position = turtle.pos()
num = len(points) #mod
for i in range(0,num):
rem = (i*mult) % num
start = points[i]
end = points[rem]
turtle.penup()
turtle.goto(start)
turtle.pendown()
turtle.goto(end)
drawLines(pen, points, 2)
increment = []
for i in range(1001):
increment.append(i/10.0)
for i in increment:
pen.color(255-10*i, 10*i+100, 15*i)
drawLines(pen, listePoints, i)
pen.clear()
source https://stackoverflow.com/questions/67762493/drawing-modular-multiplication-circle-using-turtle
Comments
Post a Comment