Python Programs - Part 1 - Curve Stitching
Python Programs - Part 1 - Curve Stitching
Python programs
Part – 1: Curve stitching
By
Nidhi Chopra
([email protected])
Page 2 of 30
Preface
Python programs in this eBook merge geometry, coding
and stitching (home science). Its inspiration came from
the subject of home science and then geometry. Python
has features and ability to make it possible & look good in
GUI.
Copyright
© Nidhi Chopra
Page 3 of 30
Index
Introduction to Python
Python is a high-level, general-purpose programming
language. It supports multiple programming paradigms,
including structured (particularly procedural), object-
oriented and functional programming. It is often
described as a "batteries included" language due to its
comprehensive standard library.
Page 5 of 30
Basic Commands
import turtle
arr_list = []
t = turtle.Turtle()
t.hideturtle()
t.pensize(2)
t.speed(30)
#t.circle(3) #marking center
t.penup()
t.goto(0,-300)
t.pendown()
r = 300
t.pencolor("green")
t.circle(r)
Page 8 of 30
t.penup()
t.goto(0,0) #go back to center
t.lt(180)
t.pencolor("blue")
for i in range(360):
t.fd(300)
arr_list.append(t.pos())
t.pendown()
t.circle(1)
t.penup()
#t.rt(180)
t.bk(300)
t.rt(1) #360/360
print(i, arr_list[i])
#connecting
Page 9 of 30
t.pencolor("red")
t.goto(arr_list[2])
for j in range(1, 600):
if j < 360:
t.goto(arr_list[j])
else:
t.goto(arr_list[j % 360])
p=j*2
t.pendown()
if p < 360:
t.goto(arr_list[p])
else:
t.goto(arr_list[p % 360])
t.penup()
Page 10 of 30
import turtle
arr_list = []
t = turtle.Turtle()
t.hideturtle()
t.pensize(2)
t.speed(30)
#t.circle(3) #marking center
t.penup()
t.goto(0,-300)
t.pendown()
r = 300
t.pencolor("green")
t.circle(r)
Page 12 of 30
t.penup()
t.goto(0,0) #go back to center
t.lt(180)
t.pencolor("blue")
for i in range(360):
t.fd(300)
arr_list.append(t.pos())
t.pendown()
t.circle(1)
t.penup()
#t.rt(180)
t.bk(300)
t.rt(1) #360/360
print(i, arr_list[i])
#connecting
Page 13 of 30
t.pencolor("brown")
t.goto(arr_list[3])
for j in range(1, 600):
if j < 360:
t.goto(arr_list[j])
else:
t.goto(arr_list[j % 360])
p=j*3
t.pendown()
if p < 360:
t.goto(arr_list[p])
else:
t.goto(arr_list[p % 360])
t.penup()
Page 14 of 30
Program 3: Parabola
Page 17 of 30
Code3: Parabola
import turtle
arr_list = []
a_list = []
# Axis
t = turtle.Turtle()
t.hideturtle()
t.pensize(2)
t.speed(0)
t.penup()
t.goto(-300, -300)
t.pendown()
#t.circle(3) #marking origin
t.goto(-300, 300)
t.penup()
t.goto(-300,-300)
Page 18 of 30
t.pendown()
t.goto(300, -300)
t.penup()
t.goto(-300, -300)
#store coordimnates
t.pencolor("blue")
for i in range(100):
arr_list.append(t.pos())
t.fd(6)
t.pendown()
t.circle(1)
t.penup()
#print(i, arr_list[i])
t.goto(-300, -300)
t.lt(90)
for i in range(100):
Page 19 of 30
a_list.append(t.pos())
t.fd(6)
t.pendown()
t.circle(1)
t.penup()
#print(i, a_list[i])
#connecting
t.pensize(1)
t.pencolor("orange")
for i in range(0, 99, 1):
t.goto(arr_list[i])
t.pendown()
t.goto(a_list[99-i])
t.penup()
Page 20 of 30
import turtle
a_list = []
b_list = []
c_list = []
d_list = []
t = turtle.Turtle()
t.hideturtle()
turtle.Screen().bgcolor("black")
t.pensize(1)
t.speed(0)
t.pencolor("blue")
for i in range(3):
t.fd(300) #lines black - invisible in black bkg
Page 22 of 30
t.goto(0,0)
t.lt(120)
#store coordinates
t.pencolor("cyan")
for i in range(100):
a_list.append(t.pos())
t.fd(3)
t.pendown()
t.circle(1)
t.penup()
#print(i, a_list[i])
t.goto(0,0)
t.lt(120)
for i in range(100):
b_list.append(t.pos())
t.fd(3)
Page 23 of 30
t.pendown()
t.circle(1)
t.penup()
#print(i, b_list[i])
t.goto(0,0)
t.lt(120)
for i in range(100):
c_list.append(t.pos())
t.fd(3)
t.pendown()
t.circle(1)
t.penup()
#print(i, c_list[i])
#connecting
t.pensize(1)
t.pencolor("white")
Page 24 of 30
References:
1. Curve Stitching: The Art of Sewing Beautiful
Mathematical Patterns by John Millington, Tarquin,
1989
2. Wikipedia
3. Various academic pages and channels on YouTube
Page 29 of 30
About author
Coming soon