knit-graphs 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- knit_graphs-0.0.6.dist-info/licenses/LICENSE → LICENSE +21 -21
- README.md +75 -0
- docs/Makefile +20 -0
- docs/make.bat +35 -0
- docs/source/api/knit_graphs.artin_wale_braids.rst +58 -0
- docs/source/api/knit_graphs.rst +74 -0
- docs/source/conf.py +335 -0
- docs/source/index.rst +71 -0
- docs/source/installation.rst +67 -0
- knit_graphs/Course.py +156 -104
- knit_graphs/Knit_Graph.py +249 -186
- knit_graphs/Knit_Graph_Visualizer.py +680 -0
- knit_graphs/Loop.py +141 -155
- knit_graphs/Pull_Direction.py +68 -23
- knit_graphs/Yarn.py +424 -267
- knit_graphs/__init__.py +3 -3
- knit_graphs/_base_classes.py +173 -0
- knit_graphs/artin_wale_braids/Crossing_Direction.py +74 -15
- knit_graphs/artin_wale_braids/Loop_Braid_Graph.py +95 -62
- knit_graphs/artin_wale_braids/Wale.py +169 -93
- knit_graphs/artin_wale_braids/Wale_Braid.py +50 -30
- knit_graphs/artin_wale_braids/Wale_Braid_Word.py +99 -54
- knit_graphs/artin_wale_braids/Wale_Group.py +136 -88
- knit_graphs/{knit_graph_generators/basic_knit_graph_generators.py → basic_knit_graph_generators.py} +302 -248
- knit_graphs-0.0.7.dist-info/LICENSE +21 -0
- {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.7.dist-info}/METADATA +33 -24
- knit_graphs-0.0.7.dist-info/RECORD +29 -0
- {knit_graphs-0.0.6.dist-info → knit_graphs-0.0.7.dist-info}/WHEEL +1 -1
- knit_graphs/__about__.py +0 -4
- knit_graphs/knit_graph_generators/__init__.py +0 -0
- knit_graphs/knit_graph_visualizer/Stitch_Visualizer.py +0 -427
- knit_graphs/knit_graph_visualizer/__init__.py +0 -0
- knit_graphs-0.0.6.dist-info/RECORD +0 -22
knit_graphs/{knit_graph_generators/basic_knit_graph_generators.py → basic_knit_graph_generators.py}
RENAMED
|
@@ -1,248 +1,302 @@
|
|
|
1
|
-
"""Module of functions that generate basic knit graph swatches.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from knit_graphs.artin_wale_braids.Crossing_Direction import Crossing_Direction
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
child_loop =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
:
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
grand_parent = parent_loop.parent_loops[0]
|
|
147
|
-
parent_pull = knit_graph.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
"""
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
#
|
|
222
|
-
#
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
last_course = next_course
|
|
248
|
-
|
|
1
|
+
"""Module of functions that generate basic knit graph swatches.
|
|
2
|
+
|
|
3
|
+
This module provides utility functions for creating common knitting patterns and structures as knit graphs.
|
|
4
|
+
These functions serve as building blocks for testing and demonstration purposes.
|
|
5
|
+
"""
|
|
6
|
+
from knit_graphs.artin_wale_braids.Crossing_Direction import Crossing_Direction
|
|
7
|
+
from knit_graphs.Knit_Graph import Knit_Graph
|
|
8
|
+
from knit_graphs.Pull_Direction import Pull_Direction
|
|
9
|
+
from knit_graphs.Yarn import Yarn
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def co_loops(width: int) -> tuple[Knit_Graph, Yarn]:
|
|
13
|
+
"""Create a cast-on row of loops forming the foundation for knitting patterns.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
width (int): The number of loops to create in the cast-on row.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
tuple[Knit_Graph, Yarn]: A tuple containing the knit graph with one course of the specified width and the yarn used to create it.
|
|
20
|
+
"""
|
|
21
|
+
knit_graph = Knit_Graph()
|
|
22
|
+
yarn = Yarn(knit_graph=knit_graph)
|
|
23
|
+
for _ in range(0, width):
|
|
24
|
+
_loop = yarn.make_loop_on_end()
|
|
25
|
+
return knit_graph, yarn
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def jersey_swatch(width: int, height: int) -> Knit_Graph:
|
|
29
|
+
"""Generate a rectangular knit swatch with all knit stitches in a flat sheet structure.
|
|
30
|
+
|
|
31
|
+
This creates a basic stockinette/jersey pattern where all stitches are worked as knit stitches from back to front.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
width (int): The number of stitches per course (horizontal row).
|
|
35
|
+
height (int): The number of courses (vertical rows) in the swatch.
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Knit_Graph: A knit graph representing a flat rectangular swatch with all knit stitches.
|
|
39
|
+
"""
|
|
40
|
+
knit_graph, yarn = co_loops(width)
|
|
41
|
+
last_course = list(knit_graph.get_courses()[0])
|
|
42
|
+
for _ in range(0, height):
|
|
43
|
+
next_course = []
|
|
44
|
+
for parent_loop in reversed(last_course):
|
|
45
|
+
child_loop = yarn.make_loop_on_end()
|
|
46
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF)
|
|
47
|
+
next_course.append(child_loop)
|
|
48
|
+
last_course = next_course
|
|
49
|
+
return knit_graph
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def jersey_tube(tube_width: int, height: int) -> Knit_Graph:
|
|
53
|
+
"""Generate a tubular knit structure with all knit stitches worked in the round.
|
|
54
|
+
|
|
55
|
+
This creates a seamless tube by knitting in the round, where the front and back sections are connected by floats to maintain the circular structure.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
tube_width (int): The number of stitches per course on the front side of the tube.
|
|
59
|
+
height (int): The number of courses (vertical rows) in the tube.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
Knit_Graph: A knit graph representing a seamless tube with all knit stitches.
|
|
63
|
+
"""
|
|
64
|
+
knit_graph, yarn = co_loops(tube_width * 2)
|
|
65
|
+
last_course = [*knit_graph.get_courses()[0]]
|
|
66
|
+
|
|
67
|
+
def _set_tube_floats() -> None:
|
|
68
|
+
"""Internal helper function to set up float connections between front and back of tube."""
|
|
69
|
+
front_loops = last_course[0:tube_width]
|
|
70
|
+
back_loops = last_course[tube_width:]
|
|
71
|
+
for first_front, second_front, back in zip(front_loops[0:-1], front_loops[1:], reversed(back_loops)):
|
|
72
|
+
yarn.add_loop_behind_float(back, first_front, second_front)
|
|
73
|
+
for (first_back, second_back, front) in zip(back_loops[0:-1], back_loops[1:], reversed(front_loops)):
|
|
74
|
+
yarn.add_loop_in_front_of_float(front, first_back, second_back)
|
|
75
|
+
|
|
76
|
+
_set_tube_floats()
|
|
77
|
+
for _ in range(0, height):
|
|
78
|
+
next_course = [yarn.make_loop_on_end() for _p in last_course]
|
|
79
|
+
for parent_loop, child_loop in zip(last_course, next_course):
|
|
80
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF)
|
|
81
|
+
last_course = next_course
|
|
82
|
+
_set_tube_floats()
|
|
83
|
+
return knit_graph
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def kp_rib_swatch(width: int, height: int) -> Knit_Graph:
|
|
87
|
+
"""Generate a knit-purl ribbing swatch with alternating wales of knit and purl stitches.
|
|
88
|
+
|
|
89
|
+
This creates a 1x1 ribbing pattern where knit and purl wales alternate, maintaining their stitch type throughout the height of the swatch for a stretchy, textured fabric.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
width (int): The number of stitches per course (horizontal row).
|
|
93
|
+
height (int): The number of courses (vertical rows) in the swatch.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
Knit_Graph: A knit graph representing a ribbed swatch with alternating knit and purl wales.
|
|
97
|
+
"""
|
|
98
|
+
knit_graph, yarn = co_loops(width)
|
|
99
|
+
last_course = knit_graph.get_courses()[0]
|
|
100
|
+
next_course = []
|
|
101
|
+
next_pull = Pull_Direction.BtF
|
|
102
|
+
for parent_loop in reversed(last_course):
|
|
103
|
+
child_loop = yarn.make_loop_on_end()
|
|
104
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=next_pull)
|
|
105
|
+
next_pull = next_pull.opposite()
|
|
106
|
+
next_course.append(child_loop)
|
|
107
|
+
last_course = next_course
|
|
108
|
+
for _ in range(1, height):
|
|
109
|
+
next_course = []
|
|
110
|
+
for parent_loop in reversed(last_course):
|
|
111
|
+
grand_parent = parent_loop.parent_loops[0]
|
|
112
|
+
parent_pull = knit_graph.get_pull_direction(grand_parent, parent_loop)
|
|
113
|
+
assert isinstance(parent_pull, Pull_Direction)
|
|
114
|
+
child_loop = yarn.make_loop_on_end()
|
|
115
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=parent_pull)
|
|
116
|
+
next_course.append(child_loop)
|
|
117
|
+
last_course = next_course
|
|
118
|
+
return knit_graph
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def seed_swatch(width: int, height: int) -> Knit_Graph:
|
|
122
|
+
"""Generate a seed stitch swatch with a checkerboard pattern of knit and purl stitches.
|
|
123
|
+
|
|
124
|
+
This creates a textured fabric where each stitch alternates between knit and purl both horizontally and vertically, creating a bumpy, non-curling fabric texture.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
width (int): The number of stitches per course (horizontal row).
|
|
128
|
+
height (int): The number of courses (vertical rows) in the swatch.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
Knit_Graph: A knit graph representing a seed stitch swatch with checkerboard knit-purl pattern.
|
|
132
|
+
"""
|
|
133
|
+
knit_graph, yarn = co_loops(width)
|
|
134
|
+
last_course = knit_graph.get_courses()[0]
|
|
135
|
+
next_course = []
|
|
136
|
+
next_pull = Pull_Direction.BtF
|
|
137
|
+
for parent_loop in reversed(last_course):
|
|
138
|
+
child_loop = yarn.make_loop_on_end()
|
|
139
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=next_pull)
|
|
140
|
+
next_pull = next_pull.opposite()
|
|
141
|
+
next_course.append(child_loop)
|
|
142
|
+
last_course = next_course
|
|
143
|
+
for _ in range(1, height):
|
|
144
|
+
next_course = []
|
|
145
|
+
for parent_loop in reversed(last_course):
|
|
146
|
+
grand_parent = parent_loop.parent_loops[0]
|
|
147
|
+
parent_pull = knit_graph.get_pull_direction(grand_parent, parent_loop)
|
|
148
|
+
assert isinstance(parent_pull, Pull_Direction)
|
|
149
|
+
child_loop = yarn.make_loop_on_end()
|
|
150
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=parent_pull.opposite())
|
|
151
|
+
next_course.append(child_loop)
|
|
152
|
+
last_course = next_course
|
|
153
|
+
return knit_graph
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def kp_mesh_decrease_left_swatch(width: int, height: int) -> Knit_Graph:
|
|
157
|
+
"""Generate a mesh pattern with left-leaning decreases and yarn overs in knit-purl ribbing.
|
|
158
|
+
|
|
159
|
+
This creates an openwork mesh pattern where purl stitches are decreased leftward on even courses and replaced with yarn overs,
|
|
160
|
+
creating decorative holes in the fabric while maintaining the overall stitch count.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
width (int): The number of stitches per course (horizontal row).
|
|
164
|
+
height (int): The number of courses (vertical rows) in the swatch.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
Knit_Graph: A knit graph representing a mesh swatch with left-leaning decreases and yarn overs.
|
|
168
|
+
"""
|
|
169
|
+
# k<o k<o k <-: 1->2
|
|
170
|
+
# |\ |\
|
|
171
|
+
# k p k p k ->: 0->1
|
|
172
|
+
# 0 1 2 3 4
|
|
173
|
+
knit_graph, yarn = co_loops(width)
|
|
174
|
+
last_course = knit_graph.get_courses()[0]
|
|
175
|
+
next_course = []
|
|
176
|
+
next_pull = Pull_Direction.BtF
|
|
177
|
+
for parent_loop in reversed(last_course):
|
|
178
|
+
child_loop = yarn.make_loop_on_end()
|
|
179
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=next_pull)
|
|
180
|
+
next_pull = next_pull.opposite()
|
|
181
|
+
next_course.append(child_loop)
|
|
182
|
+
last_course = next_course
|
|
183
|
+
for _ in range(1, height):
|
|
184
|
+
next_course = []
|
|
185
|
+
for parent_loop in reversed(last_course):
|
|
186
|
+
child_loop = yarn.make_loop_on_end()
|
|
187
|
+
grand_parent = parent_loop.parent_loops[0]
|
|
188
|
+
parent_pull = knit_graph.get_pull_direction(grand_parent, parent_loop)
|
|
189
|
+
if parent_pull is Pull_Direction.BtF: # knits stay in decrease at bottom of stack
|
|
190
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF, stack_position=0)
|
|
191
|
+
prior_parent = yarn.prior_loop(parent_loop)
|
|
192
|
+
if prior_parent is not None and prior_parent in last_course:
|
|
193
|
+
knit_graph.connect_loops(prior_parent, child_loop, pull_direction=Pull_Direction.FtB, stack_position=1)
|
|
194
|
+
next_course.append(child_loop)
|
|
195
|
+
last_course = next_course
|
|
196
|
+
next_course = []
|
|
197
|
+
for parent_loop in reversed(last_course):
|
|
198
|
+
child_loop = yarn.make_loop_on_end()
|
|
199
|
+
if len(parent_loop.parent_loops) == 0:
|
|
200
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.FtB)
|
|
201
|
+
else:
|
|
202
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF)
|
|
203
|
+
next_course.append(child_loop)
|
|
204
|
+
last_course = next_course
|
|
205
|
+
return knit_graph
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def kp_mesh_decrease_right_swatch(width: int, height: int) -> Knit_Graph:
|
|
209
|
+
"""Generate a mesh pattern with right-leaning decreases and yarn overs in knit-purl ribbing.
|
|
210
|
+
|
|
211
|
+
This creates an openwork mesh pattern where purl stitches are decreased rightward on even courses and replaced with yarn overs,
|
|
212
|
+
creating decorative holes in the fabric while maintaining the overall stitch count.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
width (int): The number of stitches per course (horizontal row).
|
|
216
|
+
height (int): The number of courses (vertical rows) in the swatch.
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
Knit_Graph: A knit graph representing a mesh swatch with right-leaning decreases and yarn overs.
|
|
220
|
+
"""
|
|
221
|
+
# k o>k o>k <-: 1->2
|
|
222
|
+
# /| /|
|
|
223
|
+
# k p k p k ->: 0->1
|
|
224
|
+
# 0 1 2 3 4
|
|
225
|
+
knit_graph, yarn = co_loops(width)
|
|
226
|
+
last_course = knit_graph.get_courses()[0]
|
|
227
|
+
next_course = []
|
|
228
|
+
next_pull = Pull_Direction.BtF
|
|
229
|
+
for parent_loop in reversed(last_course):
|
|
230
|
+
child_loop = yarn.make_loop_on_end()
|
|
231
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=next_pull)
|
|
232
|
+
next_pull = next_pull.opposite()
|
|
233
|
+
next_course.append(child_loop)
|
|
234
|
+
last_course = next_course
|
|
235
|
+
for _ in range(1, height):
|
|
236
|
+
next_course = []
|
|
237
|
+
for parent_loop in reversed(last_course):
|
|
238
|
+
child_loop = yarn.make_loop_on_end()
|
|
239
|
+
grand_parent = parent_loop.parent_loops[0]
|
|
240
|
+
parent_pull = knit_graph.get_pull_direction(grand_parent, parent_loop)
|
|
241
|
+
if parent_pull is Pull_Direction.BtF: # knits stay in decrease at bottom of stack
|
|
242
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF, stack_position=0)
|
|
243
|
+
next_parent = yarn.next_loop(parent_loop)
|
|
244
|
+
if next_parent is not None:
|
|
245
|
+
knit_graph.connect_loops(next_parent, child_loop, pull_direction=Pull_Direction.FtB, stack_position=1)
|
|
246
|
+
next_course.append(child_loop)
|
|
247
|
+
last_course = next_course
|
|
248
|
+
next_course = []
|
|
249
|
+
for parent_loop in reversed(last_course):
|
|
250
|
+
child_loop = yarn.make_loop_on_end()
|
|
251
|
+
if len(parent_loop.parent_loops) == 0:
|
|
252
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.FtB)
|
|
253
|
+
else:
|
|
254
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=Pull_Direction.BtF)
|
|
255
|
+
next_course.append(child_loop)
|
|
256
|
+
last_course = next_course
|
|
257
|
+
return knit_graph
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def twist_cable(width: int, height: int) -> Knit_Graph:
|
|
261
|
+
"""Generate a twisted cable pattern with alternating crossing directions and purl separators.
|
|
262
|
+
|
|
263
|
+
This creates a cable pattern with 1x1 twists that alternate direction every two rows, separated by purl wales to make the cable structure more prominent.
|
|
264
|
+
|
|
265
|
+
Args:
|
|
266
|
+
width (int): The number of stitches per course (horizontal row).
|
|
267
|
+
height (int): The number of courses (vertical rows) in the swatch.
|
|
268
|
+
|
|
269
|
+
Returns:
|
|
270
|
+
Knit_Graph: A knit graph representing a twisted cable pattern with alternating crossing directions.
|
|
271
|
+
"""
|
|
272
|
+
# p k\k p ->: 3-4
|
|
273
|
+
# p k k p <-: 2-3
|
|
274
|
+
# p k/k p ->: 1-2
|
|
275
|
+
# p k k p <-: 0-1
|
|
276
|
+
# 0 1 2 3
|
|
277
|
+
knit_graph, yarn = co_loops(width)
|
|
278
|
+
last_course = knit_graph.get_courses()[0]
|
|
279
|
+
next_course = []
|
|
280
|
+
pull_directions = [Pull_Direction.FtB, Pull_Direction.BtF, Pull_Direction.BtF, Pull_Direction.FtB]
|
|
281
|
+
for i, parent_loop in enumerate(reversed(last_course)):
|
|
282
|
+
child_loop = yarn.make_loop_on_end()
|
|
283
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=pull_directions[i % 4])
|
|
284
|
+
next_course.append(child_loop)
|
|
285
|
+
last_course = next_course
|
|
286
|
+
crossing = Crossing_Direction.Over_Right
|
|
287
|
+
for r in range(1, height):
|
|
288
|
+
next_course = [yarn.make_loop_on_end() for _ in last_course]
|
|
289
|
+
for i, parent_loop in enumerate(reversed(last_course)):
|
|
290
|
+
if r % 2 == 0 or i % 4 == 0 or i % 4 == 3: # not cable row (even) or in purl wale
|
|
291
|
+
child_loop = next_course[i]
|
|
292
|
+
elif i % 4 == 1:
|
|
293
|
+
child_loop = next_course[i + 1]
|
|
294
|
+
else:
|
|
295
|
+
child_loop = next_course[i - 1]
|
|
296
|
+
knit_graph.connect_loops(parent_loop, child_loop, pull_direction=pull_directions[i % 4])
|
|
297
|
+
if r % 2 == 1: # cable row
|
|
298
|
+
for left_loop, right_loop in zip(next_course[1::4], next_course[2::4]):
|
|
299
|
+
knit_graph.add_crossing(left_loop, right_loop, crossing)
|
|
300
|
+
crossing = ~crossing
|
|
301
|
+
last_course = next_course
|
|
302
|
+
return knit_graph
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Megan Hofmann
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|