0% found this document useful (0 votes)
136 views

Python Programs - Part 1 - Curve Stitching

Combination of stitching, geometry and coding

Uploaded by

Nidhi Chopra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views

Python Programs - Part 1 - Curve Stitching

Combination of stitching, geometry and coding

Uploaded by

Nidhi Chopra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Page 1 of 30

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

S.No. Topic Page


number
1 Introduction to Python 4
2 Basic Commands 5
3 Program 1: Cardioid (2’s table) 6-9
4 Program 2: Nephroid (3’stable) 10-13
5 Exercise 1 14-15
6 Program 3: Parabola 16-19
7 Program 4: Deltoid (3 point astral 20-24
star)
8 Exercise 2 25-27
9 References 28
10 About author 29
Page 4 of 30

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

S.No. Command Abbreviation Output Examples

1 FORWARD fd Moves turtle forward for fd(100)


number of times
specified

2 BACK bk Moves turtle back for bk(100)


number of times
specified

3 RIGHT rt Turns turtle right for rt(90)


number of degrees
specified

4 LEFT lt Turns turtle left for lt(90)


number of degrees
specified

5 PENUP penup Sets the turtle to move penup()


without drawing

6 PENDOWN pendown Resets to a drawing pen pendown()


when ordered to move

7 CIRCLE circle Makes a circle or radius, circle(r)


r
Page 6 of 30

Program 1: Cardioid (2’s table)


Page 7 of 30

Code 1: Cardioid (2’s table)

import turtle
arr_list = []

# Initializing the turtle

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

#mark 60 points in circle

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

Program 2: Nephroid (3's table)


Page 11 of 30

Code 2: Nephroid (3's table)

import turtle
arr_list = []

# Initializing the turtle

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

#mark 60 points in circle

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

Exercise 1: Write a python code to draw the following 8


geometric patterns (variations of the previous 2):

Trefoiloid (4's table) Quatrefoiloid (5's table)

Epicycloid with 5 cusps (6's Epicycloid with 6 cusps (7's


table) table)
Page 15 of 30

Epicycloid with 7 cusps (8's Epicycloid with 8 cusps (9's


table) table)

Epicycloid with 9 cusps Epicycloid with 10 cusps


(10's table) (11's table)
Page 16 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

Program 4: Deltoid (3 point astral star)


Page 21 of 30

Code 4: Deltoid (3 point astral star)

import turtle
a_list = []
b_list = []
c_list = []
d_list = []

# starting basic structure

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

for i in range(0, 99, 1):


t.goto(a_list[i])
t.pendown()
t.goto(b_list[99-i])
t.penup()

for i in range(0, 99, 1):


t.goto(b_list[i])
t.pendown()
t.goto(c_list[99-i])
t.penup()

for i in range(99, 0, -1):


t.goto(c_list[i])
t.pendown()
t.goto(a_list[99-i])
t.penup()
Page 25 of 30

Exercise 2: Write python code to draw the following 12


geometric designs (based on previous 2):

Two parabolas in a square Trefoil knot made using 3


parabolas in a triangle

4 parabolas in a square Zigzag parabolas


(wall art)
Page 26 of 30

Astroid (4-point astral star) 5-point astral star

6-point astral star 8 pointed star (8 radii not


shown)
Page 27 of 30

3 petal flower using 6 4 petal flower using 8


parabolas in a hexagon parabolas in a hexagon

8 parabolas in 4 squares Windmill


Page 28 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

Author, Nidhi Chopra is a writer and content creator.


Page 30 of 30

Coming soon

Python programs – part 2

You might also like