-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_code
More file actions
172 lines (158 loc) · 6.17 KB
/
python_code
File metadata and controls
172 lines (158 loc) · 6.17 KB
1
2
3
4
5
6
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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import random
import re
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import colors
final_even=[]
final_odd=[]
graphic=[]
for k in range(4):
list = []
for i in range(0, 6):
n = random.randrange(0, 2)
list.append(n)
print(list)
graphic.append(list)
odd_row1 = []
for i in list:
if i == 0:
odd_row1.append("k")
else:
odd_row1.append("sl")
print(odd_row1)
count1 = []
n = 1
odd_row1.append('NULL')
for i in range(0, 6):
if odd_row1[i] == odd_row1[i + 1]:
n += 1
else:
count1.append(n)
n = 1
print(count1)
odd_row1.remove('NULL')
count2 = []
for i in count1:
i = i * 3
count2.append(i)
print(count2)
condensed_odd_row1 = []
if odd_row1[0] == 'k':
print("k is first")
for i in range(0, len(count2)):
if i % 2 == 0:
condensed_odd_row1.append(str(count2[i]) + "k")
else:
condensed_odd_row1.append(str(count2[i]) + "sl")
else:
print("sl is first")
for i in range(0, len(count2)):
if i % 2 == 0:
condensed_odd_row1.append(str(count2[i]) + "sl")
else:
condensed_odd_row1.append(str(count2[i]) + "k")
con_odd_row1 = condensed_odd_row1.copy()
print(con_odd_row1)
final_odd.append(con_odd_row1)
condensed_odd_row1.reverse()
con_even_row1 = []
for i in condensed_odd_row1:
if re.search("k$", i):
con_even_row1.append(i.replace('k', 'p'))
else:
con_even_row1.append(i.replace('sl', 'sl'))
print(con_even_row1)
final_even.append(con_even_row1)
filename = "knit_mosaic_pattern.txt"
with open(filename, 'w') as f:
f.write('Knit Mosaic Scarf Pattern\n\n')
f.write("This pattern was inspired by my friend Phia Wilson who designs and makes scarves for fun.\n\n")
f.write("This pattern consists of a randomly generated 4 by 2.6 inch rectangular mosaic block that repeats 135 times.\n"
"There are 16,777,216 different pattern combinations that can be generated from this code!!.\n\n")
f.write("Materials\n"
"\t-255 yards worsted yarn (4) for the main color\n"
"\t-255 yards worsted yarn (4) for the contrast color\n"
"\t-US 8 (5mm) needles\n"
"\t-Stitch markers\n"
"\t-Tapestry needle\n\n")
f.write("Abbreviations\n"
"\t-CC: Contrast Color\n"
"\t-CO: Cast on\n"
"\t-k: Knit\n"
"\t-MC: Main Color\n"
"\t-p: purl\n"
"\t-pm: Place Marker\n"
"\t-pwise: Purlwise\n"
"\t-wyib: With Yarn in Back\n"
"\t-wyif: With Yarn in Front\n\n")
f.write("Size\n"
"\tCreates a 72 by 20 inch rectangular scarf once washed and blocked.\n\n")
f.write("Gauge\n"
"\t18 stitches by 24 rows = 4 inch square\n\n")
f.write("Instructions\n"
"\tCasting On\n"
"\t\tUsing US 8 needles, CO 90 stitches in MC.\n"
"\tRepeating Pattern\n"
"\t\tRow 1 (MC): "+str(final_odd[0])+" pm and repeat to end of row.\n"
"\t\t\t\t* For all odd rows, slip yarn pwise wyib * \n"
"\t\tRow 2 (MC): "+str(final_even[0])+" Repeat.\n"
"\t\t\t\t* For all even rows, slip yarn pwise wyif * \n"
"\t\tRow 3 (MC): ['18k'] Repeat.\n"
"\t\tRow 4 (MC): ['18p'] Repeat.\n"
"\t\tRow 5 (CC): "+str(final_odd[1])+" Repeat.\n"
"\t\tRow 6 (CC): "+str(final_even[1])+" Repeat.\n"
"\t\tRow 7 (CC): ['18k'] Repeat.\n"
"\t\tRow 8 (CC): ['18p'] Repeat.\n"
"\t\tRow 9 (MC): "+str(final_odd[2])+" Repeat.\n"
"\t\tRow 10 (MC): "+str(final_even[2])+" Repeat.\n"
"\t\tRows 11-12: Repeat rows 3-4.\n"
"\t\tRow 13 (CC): "+str(final_odd[3])+" Repeat.\n"
"\t\tRow 14 (CC): "+str(final_even[3])+" Repeat.\n"
"\t\tRows 15-16: Repeat rows 7-8. \n"
"\t\tRows 17-432: Repeat rows 1-16, 27 times. \n"
"\tBinding Off\n"
"\t\tStep 1: Knit 2 stitches"
"\t\tStep 2: Move those 2 stitches back to the other needle.\n"
"\t\tStep 3: Knit the 2 stitches together\n"
"\t\tStep 4: Knit 1 stitch\n"
"\t\tStep 5: Repeat steps 2-4 until there is only one stitch left.\n"
"\t\tStep 6: Cut your yarn leaving a ~5 inch tail and pull it through the last stitch.\n"
"\t\t\t\tThis will create a knot and prevent your scarf from unraveling.\n"
"\t\tStep 7: Using the tapestry needle work in all any ends.\n"
"\t\tStep 8: Wash and block you scarf :)\n"
"\tAdding Fringe (optional)\n"
"\t\tStep 1: Cut 4, 8 inch strands of yarn\n"
"\t\tStep 2: Holding the 4 strands together, use the crochet hook to pull the center of each\n"
"\t\t\t\tstrand through a stitch along the bottom/top of the scarf. This will create a loop.\n"
"\t\tStep 3: Pull the fridge ends through the loop, and tighten\n"
"\t\tStep 4: Trim fringe ends to desired length\n"
"\t\tStep 5: Repeat steps 1-4 to add additional fringe wherever desired\n\n")
f.write("Coded by: Denise Rauschendorfer (2022)\n")
f.close()
mc_knit = [0, 0, 0, 0, 0, 0]
cc_knit = [1, 1, 1, 1, 1, 1]
final_graphic = []
for i in range(0, 4):
if i % 2 == 0:
final_graphic.append(graphic[i])
final_graphic.append(mc_knit)
else:
flip = []
for j in graphic[i]:
if j == 0:
flip.append(1)
else:
flip.append(0)
final_graphic.append(flip)
final_graphic.append(cc_knit)
final_graphic.reverse()
cmap = colors.ListedColormap(['red', 'white'])
fig, ax = plt.subplots()
ax.grid(color='black', linewidth=2)
ax.set_xticks(np.arange(-0.5, 6, 1))
ax.set_yticks(np.arange(-0.5, 8, 1))
ax.set_xticklabels([])
ax.set_yticklabels([])
plt.title("Repeating Rectangular Block", fontsize=20, color="black")
plt.imshow(final_graphic, cmap=cmap)
plt.savefig("knit_mosaic_graphic_pattern.jpg")