Scratch Crochet Pattern Maker

by Ecordeir3295 in Circuits > Computers

1110 Views, 9 Favorites, 0 Comments

Scratch Crochet Pattern Maker

B7A22C3D-15ED-4B8C-B524-8FD35A504C75.jpeg

This instructable is going to be showing you how to make a crochet pattern maker using scratch. That might sound a bit confusing, but what the scratch code you’ll make does is let someone draw/plan out a design, then write out a pattern for crochet based on it, so you can easily crochet the exact pattern you drew.

Supplies

  • An account on scratch
  • Some device to use scratch on

Thats really all that’s necessary! But if you want to be able to actually crochet the patterns the code writes you will need some basic crochet supplies, those being:

  • A crochet hook
  • Yarn

Making a Scratch Account

The very first step is to make an account on scratch if you don’t have one. This is simple, as all you have to do is go to the scratch website (scratch.mit.edu), click sign up, and follow the steps it gives.

If you already have an account just log in if you aren’t already.

Create a New Project on Scratch

To create a new project click the create button near the top left. You’ll also need to give your project a name. I’d recommend something along the lines of "crochet pattern maker", but it doesn’t matter much.

Edit the Costume

1DB195C3-C028-4540-A599-B09CB790C865.jpeg
127B6B5F-444C-4F6A-BEDC-A51B0BD222AB.jpeg
F04D9577-EB1C-44E1-A7ED-E358E7DD4D94.jpeg

Next you need to edit your first sprite’s costume. The button is labeled costumes, and is on top of where the code is. Click the paintbrush icon to draw a new sprite, then select the other costumes and click the trash to delete them. Now you can draw a new one. This costume will represent the stitches, and is what you colour to make the design. It could be dots, pixels, an actual drawing of a crochet stitch, or pretty much anything else (but keeping it simple is best). Don’t worry too much about size and colour yet, since size can be adjusted using ‘set size to’ blocks and colour will be changed later. Also make sure to only draw one, because even though it will be multiple stitches you don’t need to worry about that right now.

Make a Start/title Screen (Optional)

ED20103B-6989-40F9-A8CD-8907BAFA697F.jpeg
E1989E9E-52CD-4224-9A36-FEE35128C4D1.jpeg
27EDC9E0-D4C5-43EE-A4BA-73D78EDD1CA4.jpeg

This isn’t necessary but if you want to add something at the start you can. Do this by making a new backdrop. You could also make a new sprite (which is what I did for most of it) but backdrops are simpler so I’m going to explain using backdrops, even though you could just use another sprite. If you do, whenever I say to do ‘switch backdrop to’ you can replace that with making the sprite you’re using as a backdrop have ‘when I receive __, show’ for whatever broadcast. Also using ‘set drag mode to not draggable’ is helpful. Anyways, create a new backdrop by pressing the button at the bottom of the stage part and click the paintbrush to draw it. Then add text to say whatever you want the starting screen to say.

Next add a new sprite by clicking the button with a face and a plus. This sprite will be the button to start and can look however you like. Now, onto the actual code. Drag a ‘when green flag clicked’ and a ‘when this sprite clicked’ block from the events tab. Under the green flag start put ‘show’ and ‘switch backdrop to’ from looks, and if you want it to stay in a certain place add ‘go to’ with the coordinates you want it at and ‘set drag mode not draggable’ from sensing. Under when sprite clicked go to events and find the broadcast block. Name it start (or something else), and put it underneath. This code uses broadcast blocks a lot, and what they do is make it easy to have multiple sprites do things at the same trigger, since there are also ‘when I receive’ for broadcasts. Then add ‘switch backdrop to’ the name of your backdrop and ‘hide’ from looks. You'll also need to keep another backdrop just plain white and name it something like "blank".

Set the Pattern Length and Width to User Input

A368B6E2-6D33-45E0-A409-F82AD529CA3A.jpeg
6CFAD569-7216-4C29-B430-D4487FD9F26C.jpeg

Next you’ll have the length and width of the pattern be input by the person using it. The first thing you need to do is add two variables, length and width (I actually named them height and width but any is fine).

First make a new sprite. I just made it hidden but if you want you can actually make the sprite look like something.

For the code, if you added a start screen you’ll need a ‘when I receive’ block for whatever you called the broadcast from the start button, and add a 'switch backdrop to _' for the blank one. If you didn’t add a start screen just use a ‘when green flag clicked’ block. Under your start block you can put a hide block if you don’t want anything there, then from sensing get a ‘ask __’ block and have it ask something like “what should the width be from _ to _ stitches”. I did 2 to 15 and it kind of has to be at least 2 since you can’t just crochet 1 stitch, but you can make the limit as much as you want.

This next part you can decide how complex it should be, because I made it able to repeat the question forever if the answer isn’t a number between 2 and 15, but you could just make it as simple as if it’s not in the limit it says you can’t do that and resets.

If you want to do the simpler way get an if then else block from control and a greater than, less than, and an and block from operations. Get an ‘answer’ block from sensing (its round and can’t go on its own) and then put that into the greater then and type your minimum number in the other slot, it should look like answer > minimum. Then repeat the same but answer < maximum. Next put both of those in the ‘and’ block and put that in the slot next to the if then. Then get a ‘set __ to __’ block from variables and another answer block from sensing, and make it so it sets whatever variable you asked about (length or width) to answer. Then put that inside of the if then block. Next repeat the same steps but with the other variable (so if you did width first do the same but with height) and put the ‘if then else’ block that’s in inside of the if then part of the first one. Now get a ‘say’ block from looks and type something like “Only input a number between (minimum) and (maximum)” and put that block if the else of both if then else blocks. Lastly take a broadcast block and make the new broadcast “Dimensions done” or something similar, then put it after the second dimension is done.

If you wanted to do the more complicated version it’s pretty much the same idea as what I just explained, so you can copy what the screenshot shows.

Make It Duplicate Itself to Match the Dimensions

384777E2-193C-4427-96E2-335529DE11CA.jpeg
B02DFB4F-37E8-4B10-ACF9-5716A3D1316A.jpeg

Next what you’ll do is make that first sprite you made duplicate itself so it matches the dimensions of what was input. The code is in the first sprite, and starts with ‘when I receive *most recent broadcast*(dimensions done for me), then ‘set drag mode not draggable’, ‘show’, and ‘point in direction *90*’ from motion. The next few parts will depend on what you think looks best for your sprite. First you need to get a ‘move __ steps’ block from motion and test how many steps looks good when it’s duplicated. To test this get a ‘create clone of myself’ block then a ‘move __ steps’ and connect them, but don’t connect it to your starting block, just leave them off to the side. Next put in a number of steps, click them to start it, and adjust the number until you find what looks best (I did 21). Now create a variable and name it “number of steps”, then drag a ‘set __ to __’ and make it set the number of steps variable to whatever you thought looked best and put that under your starting block. Then add a repeat block over the move steps and duplicate blocks (still off to the side) and set it to repeat the maximum width you had. If it doesn’t fit get a ‘set size to __%’ block from looks and find what it fits the maximum with. You may have to adjust the number of steps to fit with the new size. Now you can delete the ones off to the side. You should also get a ‘go to x y’ block and input the x and y coordinates of the starting position so it stays in the right spot.

Next create a variable called “starting x” and get the ‘set _ to _’, and from motion get the ‘x position’ block (it’s one of the round ones). Make it ‘set *starting x* to *x position* and drag it under what you already have. That’s all the setup there is that might vary depending on the person, so now I’m going to write out the whole code. It’s not actually text, I’m just writing out what the blocks used say, everything surrounded by brackets are variables and things surrounded by ** are something you picked (not what I actually wrote). Also things that are indented under a repeat mean they’re inside the repeat block. If you’re confused you can just copy the image of it. Anyways, here’s the main code.

When I receive *dimensions done/whatever the last broadcast was*:
show
set drag mode not draggable
point in direction 90
go to *x* *y*
set size to *size you picked*%
set (# of steps) to *the number you picked*
set (starting x) to x position
Repeat (width)
create clone of myself
move (# of steps) steps
Repeat (height)-2
set x to (starting x)
change y by *- whatever your steps was*
Repeat (width)
create clone of myself
move (# of steps) steps
set x to (starting x)
change y by *- whatever your steps was*
Repeat (width)-1
create clone of myself
move (# of steps) steps

Once you’re done it should be a square/rectangle matching the dimensions that were put in.

Make Colour Variants of the Stitch

D8C157BD-2749-484E-9486-77E0B601C302.jpeg
E18B25B6-3E81-4F1D-A738-88E56023BF02.jpeg

Next you’ll need to make colour variants of the stitch. I chose to have 3 variations in saturation and 5 in brightness, but you could be less or more. This step is very tedious, but next you need to duplicate the costume and change the colour so every combination of saturation and brightness is there. The way you do this is right clicking your first costume and clicking duplicate, then select the new one, and adjust the colour.

A few combinations you probably won’t need are variations of saturation for the lowest brightness, since it will all look black anyways. Another tip I have is to name them. Trust me this makes things much easier later on). I named mine b for black, dg, dg5, and dg10 for dark grey and the saturation variants, g, g5, and g10 for grey, lg, lg5, and lg10 for light grey, and w, w5, and w10 for the lightest colours. Also the actual base colour you use doesn’t matter, since it will be changed, but I used red (and don’t worry about making variants for colour yet!).

Since I had 3 saturation options and 5 brightness options, but didn’t include any variations of saturation for the lowest brightness I had 13 in total. Also all of mine were combinations of saturation 0, 50, and 100, and brightness 0, 25, 50, 75, and 100.

Make Buttons to Change Saturation and Brightness

09DE3A74-CF97-473C-ABDF-E5ECEBBF9CE2.jpeg

This next step is to make buttons to select what colour you want to use. First make a new sprite. Then add a ‘when I receive’ block (using the broadcast for once the dimensions are finished), then add show under it. You’ll also need to get a when green flag clicked block and put hide under that. You can also add a 'go to x y' block with the coordinates for each sprite, and if you want put a forever block around it so it cant be dragged out of place. Now go to edit the costume, and choose what shape you want it to be (it’s just a button so it doesn’t really matter, but I did a square). Next you need to make a new sprite for each of the variations of saturation and brightness you have, and then colour them corresponding to it. For the saturation ones you can pick any colour to use as a base, since this is just a button and the colour doesn’t affect anything. As you can see in the photo, since I had 5 brightness options, 0, 25, 50, 75, and 100 I made 5 squares and made each of them one of the colours. Once you have all of them made either drag them into a spot you like or use a ‘go to x y’ block. Then get a ‘set drag mode not draggable’ block and put it under the show block. Also it's helpful to name the sprites based on what they are. so the 50% saturation could be s50, and others could be s0, s100, b0, b50, b100, etc.

Make a Button to Change Colour

Make a new sprite and copy paste the same shape that you used for saturation and brightness. Next choose a colour to use as the base. Making it the lightest and most saturated is best so you can clearly see the colours and its not too dark, but once again it could be anything. Change the shape's colour and drag it into wherever you like it, then copy and paste the code from the other buttons so it also only shows with the broadcast and isn’t draggable. You can also add labels by making a new sprite and adding text to the costume, and use the same code from the buttons to make it show at the right times again.

Also under the when sprite clicked put a 'set colour to 0' block. You should also repeat this for every variable you have so far, and all of them in the future. Its just so they reset at the beginning and don't keep adding up forever.

Add Code to the Saturation and Brightness Buttons

Screenshot 2023-06-20 104523.png
Screenshot 2023-06-20 104706.png
Screenshot 2023-06-20 104828.png

Now we need to make the buttons actually do something. First go to variables and create one called colour, one called saturation, and one called brightness. Also create a variable called full colour. This isn’t needed right now but will be later.

I’ll start with the code for saturation and brightness, since colour is different than the other two. The code is going to be pretty much the exact same in all of them, so pick any of them to start with. First you need a 'when this sprite clicked' block, and a 'change _ to _' block from variables. Now depending on what sprite you chose to start with the number and variable you put will be different. If you're starting with one of the buttons for saturation, make it 'set saturation to _', and if its brightness set the variable to brightness. As for what number to put, if you named your buttons just set it to the number on your button, but if not go to costumes, colour pick the sprite by pressing the eyedropper tool, and check what number you put for it. That's what you'll set the number to. Then you can copy and paste that into all the other brightness and saturation buttons, just remember to change the variables and numbers. Also you can test if it works by first making sure the saturation and brightness variables are showing, then click a button and see if it changes the variable to the right number.

This next part is just set up for later, but next you need to get another ‘set __ to __’, the round versions of colour, saturation, and brightness, and a ton of join blocks from operations. Combine them to be ‘set full colour to {C (colour) S (saturation) B (brightness)}’. The capital letters are just text and the ones surrounded by normal brackets are variables (just copy the photo if you don't understand).

Add Code to the Colour Button

4DEE441D-767A-4F4C-95CD-CAA4D8B4CF51.jpeg

Now to make it for the colour button. First get a ‘when this sprite clicked’ block from events, then a ‘change colour effect by __’ from looks, set the amount it changes by to 10, and put it under the when clicked block. What that block does is change the colour of the actual sprite so you can see what it is when you choose colours. Next, get a ‘change __ by __’ from variables and set it to change colour by 10. Then get an if then block, a greater than block, and the round version of colour. Combine them to be ‘if colour > 190 then’, then get a ‘set __ to __’, change it to ‘set colour to 0’, and put it in the if then block. This is just so the colour variable doesn’t go up to forever, and is always the same numbers. You also need to copy the set full colour to thing from one of the other buttons.

To test this one make sure the colour variable is showing, then click the button and see if it changes the sprite's colour and the colour variable every time.

Make Stitches Change Colours When Clicked

Screenshot 2023-06-21 091106.png

This next step is pretty much just a lot of code, so I'm just going to write it out the same way I did in step 6, but first I should mention that if you did a different amount of options for saturation or brightness than me it will be different, but it should be easier to modify it to fit what you did. Also when square brackets are used its because its a block that multiple things are in, so for example in 'if [(brightness) = 100] then:' the square brackets arec there because its a '_ = _' block that brightness and 100 are in.

When this sprite clicked:
set drag mode not draggable
set colour effect to (colour)
if [(brightness) = 100] then):
switch costume to black
clear graphic effects
if [(brightness) = 75] then):
if [(brightness) = 75] and [(saturation) = 50] then):
switch costume to dg5
else:
if [(brightness) = 75] and [(saturation) = 100] then):
switch costume to dg10
else:
switch costume to dg
clear graphic effects
if [(brightness) = 50] then):
if [(brightness) = 50] and [(saturation) = 50] then):
switch costume to g5
else:
if [(brightness) = 50] and [(saturation) = 100] then):
switch costume to g10
else:
switch costume to g
clear graphic effects
if [(brightness) = 25] then):
if [(brightness) = 25] and [(saturation) = 50] then):
switch costume to lg5
else:
if [(brightness) = 25] and [(saturation) = 100] then):
switch costume to lg10
else:
switch costume to lg
clear graphic effects
if [(brightness) = 0] then):
if [(brightness) = 0] and [(saturation) = 50] then):
switch costume to w5
else:
if [(brightness) = 0] and [(saturation) = 100] then):
switch costume to w10
else:
switch costume to w
clear graphic effects

Add a Done Button

Screenshot 2023-06-21 093423.png
Screenshot 2023-06-21 094257.png

Next you need to add a button to confirm that you're done with the button. I made mine look like a checkmark, which you can find by clicking the search instead of the paintbrush when making a costume, and searching up "button". But it could be something that says done or anything else.

First get a when green flag clicked block and add a hide block under it. Then 'when I receive _' for the broadcast when dimensions are done and add a show, set drag mode not draggable, and if you want a go to x y for the coords you want it at. Then get a when this sprite clicked and make a new broadcast called "finished'' or whatever else works.

Add a Confirm for the Done Button (optional)

Screenshot 2023-06-21 094735.png
Screenshot 2023-06-21 095041.png
Screenshot 2023-06-21 095229.png
Screenshot 2023-06-21 094651.png

I also made it have a pop up asking to confirm that you're done, but that isn't necessary. If you don't want to add that skip this step. You'll need to duplicate the first costume and add text to the side asking ''Are you sure you're finished?'', then make two new sprites and make ones costume say yes and the other say no (if its just text you could add some white behind so its easier to click). Now go back to the first done button and add a 'switch costume to _' for the costume without text under the 'when I receive dimensions done' part. Then make a new broadcast called confirm or yes or no, and replace the broadcast "finished'' from under when this sprite clicked. Then still under when this sprite clicked, add a 'switch costume to _' for the costume with extra text.

Now move back to one of the yes or no buttons, and add a when green flag clicked and do the same as the other buttons, add a hide, set drag mode not draggable, and if you want a go to x y block. Then get a 'when I receive _' and change it to the yes or no broadcast (the one that the main button broadcasts when clicked) and put a show underneath it. Now copy what you have so far onto the other button, so they both have the same code, then switch to the yes button and get a when sprite clicked block. Add the broadcast ''finished'' underneath, then switch to the no button and get a when sprite clicked but make a new broadcast called ''keep going'' and make it broadcast that instead.

Now go back to the main button and add a when I receive for both of the broadcasts, put a hide under the yes one, and a 'switch costume to _' the first costume (the one without text) under the no broadcast.

Add a Choice of What Kind of Stitch

Screenshot 2023-06-21 093037.png
Screenshot 2023-06-21 103308.png

For this step you can do one of two things. The first is what I did, and is making a screen to choose between having the pattern write single crochet, half double crochet, or double crochet. The second option is to just pick one and only use that. If you want to do the second option you can skip this step and on step 22 just type in the stitch you're using instead of putting in a variable. Otherwise, first make a new backdrop and add text asking what kind of stitch you want to use (name this something like ''Choose the stitch''). Then make 3 new sprites (one for sc, hdc, and dc, but you could do a different amount), and edit their costumes to be text of what stitch it is. Also adding a white square or other shape behind the text helps so it still counts a being clicked even if you don't click directly on the letters (this is shown in one of the photos). Another tip is to copy the text of one costume into the other and edit it without dragging it so they're on the same level and not uneven.

Starting in one of the sprites get a when green flag clicked block and put hide under, then get a 'when I receive block' and have it be when it receives finished, or whatever you called the broadcast you made in the last steps. Then put a set drag mode not draggable, and a show block. Copy that to the rest of the stitch type buttons. Next put a 'switch backdrop to _' for the backdrop you just made under the when I receive finished (you just need to do this in one of the buttons). Now get a when this sprite clicked block and make two new variables, stitch type and stitch abbreviation. Under when this sprite clicked add two 'set _ to _' blocks, and change them to each of the variables you just made. Depending on which stitch you did first (and what you included in general) you'll change them to different things. I'll start with single crochet, in which case in the single crochet button's code, have it set stitch type to "single crochet'' and stitch abbreviation to ''sc'', for half double crochet do ''half double crochet'' and ''hdc'' in the hdc button, and for double do ''double crochet'' and ''dc'' in the dc button. Then in all the buttons after the variables are set add a hide block and add a new broadcast named ''stitch chosen'' after it (I was pretty unorganized with naming variables and broadcasts and I named mine done fr which is not very descriptive, but I think you have to manually rename it every time its been used and I don't want to do that. So if you see that broadcast just know it's for when the stitch is chosen). Then in all the buttons add a 'when I receive _' for stitch chosen and add hide.

Now that that's done we can get onto the actual pattern writing part.

Track Colour Changes

0B96C3A0-5164-4F5F-ACAA-9126D80D753A.jpeg
50AC61AC-9229-45DE-80BD-AFE60AC2D1D2.jpeg
547EE4E8-3776-44A5-A51C-0F6FCA7710D8.jpeg
CFB39DD0-AC23-4C23-B641-0D3A914A3A9F.jpeg

This step is set up for writing the pattern, and first you’ll need to go back to the first sprite (the one for the stitches). Next you need to make a list. This is found below variables (it doesn’t have a tab to click on which makes it easy to miss), and once you found it click make a list and name it "colours" or "colour" tracking. You also need to make two new variables, one named x position and one named y position.

Now that that’s set up, first you need a ‘when this sprite clicked’ block, then you need to make the "full colour" variable change, and since this part of the code is already in the buttons to change colour, you can copy it from there. If you can’t find it you need to get ‘set __ to __’, the round versions of colour, saturation, and brightness, and a ton of join blocks from operations. Combine them to be ‘set full colour to {C (colour) S (saturation) B (brightness)}’. The capital letters are just text and the ones surrounded by normal brackets are variables (just copy the photo if you don't understand). That goes under when this sprite clicked.

This next part will be completely different depending on whether person, but the first thing you need to do is get two ‘set _ to _’ blocks from variables and set one to x position, and one to y position. You also need an x position and y position block from motion, four ‘_ - _’ blocks, two ‘_ / _’ blocks, and one ‘_ + _’ block, all from operations. Now you need to find out what x and y the sprite for stitches starts at, and how many steps it moves, which if you don’t remember you can find by looking at the part of the code for moving in this sprite that has a ‘go to *x* *y*’ and a ‘move _ steps’ block. Now put the x position from motion into the left side of one of the minus blocks from operations, and in the right side type the x position the sprite starts at. Then put that in the left side of a division block (the one with a slash), and type the number of steps your sprite moves by in the right side. Copy that and switch out the x position block for y position, and change the minus to the y position the sprite starts at. Now put the x position version in the left side of the plus block and make it plus one. Do the same with the y position one just minus one instead. Now put the x one into the ‘set x position to _’ block and put the y one into the y position block. Now get another ‘set _ to _’ block and have it set y position to 0 - y position (this is so the variable isn’t negative). Then connect those under the ‘set full colour to _’ part (the most recent one has to be after the first y position one).

To test if it’s working properly click on a random duplicate of the sprite. It should change x position to however many duplicates to the right it’s away from the start, and y position should do the same but however many below.

Now you need to copy what you just did (minus the when this sprite clicked), get a when I receive block for dimensions done, and connect them. Then get a repeat block, the round versions of your height and width variables, and a ‘_ * _’ block, combining them so it’s ‘repeat width * height’. Inside the repeat get an ‘add _ to _’ block from lists and type out the colour you start with in the same way that the variable full colour is (for me that was C0 S100 B0). Now go back to the when this sprite clicked code and get ‘replace item _ of _ with _’ from lists. Then using the multiply, minus, and plus blocks put the y position variable in the left side of the minus block and type 1 in the right, then put that in the right side of the multiply block with the width variable in the left side, then put that in the left side of the plus block and put the x position variable in the right, then finally put that in the first slot of the replace item block from earlier. In the replace block set the list to the one you made for colours, and in the far right put in the round version of the full colour variable. It should read like this: ‘replace item (width * y position - 1 + x position) of "colour" with (full colour)’.

Finally, to test it change the colour of the first stitch, and item one of the list should change to what the colour is. You should also test other stitches to make sure it works.

Add a Choice to Name Colours

Screenshot 2023-06-21 185322.png

What I did for this next step is have a screen where you can choose whether to name all of the colours or to have them automatically named "colour 1", "colour 2", etc, and what you do is up to you. If you don't want to name them skip ahead to step 18, if you want to always name them skip to step 19, and if you want the option for both keep reading this step.

First make a backdrop with text saying "Do you want to name the colours?", then make two new sprites, one named "name yes" and one named "name no" (or something along those lines). You'll also need to make a new broadcast named "write pattern", but these sprites wont broadcast it, just receive it. For the costumes make text saying yes for one and no for the other (I also made them look a bit more like actual buttons by changing the colour of the premade sprite "Button 3-a" and putting that behind the text). In one of them add a 'when I receive _' for the broadcast for when the stitch type is chosen, and underneath add a block to change the backdrop to the one you just made.

Now add 'when green flag clicked', 'when I receive stitch chosen', and 'when I receive write pattern' and add a hide block under each of them. Copy all the code over to the other button. In the yes button get a when this sprite clicked, make a new broadcast called 'name them' and connect the two. Then for the no button add a 'when I receive name them' block and make it hide for that too. Also add a 'switch backdrop to blank' after the 'when this sprite clicked' for both of the buttons.

Assign Colours Numbers (Optional)

Screenshot 2023-06-21 150743.png

First you need to make a variable named "name count" one named "colour #" and one named "value of colour". Then make a list called "colour names", one "colour name values", and one "replace colour #". Start the code with a when green flag clicked block and a hide block under it.

The next part of the code is very big, so I'm just going to be writing the code out for this step. It's the same rules as before, but if you're confused just copy the photo. Also things in quotes are list names.

When I receive stitch chosen:
set (colour #) to 0
Repeat length of "colours":
if {not ["colour name values" contains item (name count) of "colours"]} then:
set (value of colour) to item (name count) of "colours"
add (value of colour) to "colour name values"
change (colour #) by 1
add {join [colour (colour #)]} to "colour names"
repeat until {not ["replace colour #" contains (value of colour)]}:
replace item [item # of (value of colour) in "replace colour #"] of "replace colour #" with {join [co lour (colour #)]}
change (name count) by 1
broadcast [write pattern]

*If you made it possible to choose whether to name them replace the 'when I receive stitch chosen' with when clicked.

Name Colours (Optional)

Screenshot 2023-06-21 180111.png
Screenshot 2023-06-21 173518.png
Screenshot 2023-06-21 174841.png

For this sprite you should duplicate the sprite for stitches, since this sprite needs to change colours too and its much easier to not have to do it all again. Then you need to delete all of the code except the one for changing colours, or you could delete all of the code by right clicking where there isn't anything and just copy over the colour changing part, either way is fine.

You first need to make a variable named "colour for name", then get a 'when I receive finished' block (the broadcast from once you're done making the pattern before you choose which stitch), an 'add _ to _' from lists set to replace colour #, and a 'length of _' and 'item _ of _' also from lists. Set both of those to the list called colours. Put the 'length of colours' into the repeat block (next to the word repeat), and then put 'item 1 of colours' into 'add _ to replace colour #' and put that inside the repeat. Then put that under the 'when I receive finished' block. You also need a when green flag clicked block, and under it put 'hide', 'set name count to 0', and 'delete all of _' for the lists colour names, colour name values, and replace colour #.

Now going back to the thing for changing colours, you do need to edit this slightly. I'll start with the brightness 0 part as an example. So, where it says 'if brightness = 0' you need to get rid of the '_ = _' parts and instead replace it with a '_ contains _' from sensing, and add the round version of value of color to the left side, and in the right type B0. So for example, a part that said 'if brightness = 0 and saturation = 100' would instead be 'if value of colour contains B0 an value of colour contains S100'. Then even though its extremely tedious, you need to go through and replace all of them in that same way. The photos show what I mean. You also have to delete the part that changes the colour variable, and instead get three 'letter _ of _' from operations and put the round version of value of colour in the right, then make one letter 2, one letter 3, and on letter 4, then use join blocks from operations to combine them (they have to be in the order 2, 3 ,4). Then get a 'set _ to _', put what you just made into the right, and make it the variable 'colour for name'. Then get a 'set colour effect to _' from looks and put the round 'colour for name' into it.

One of the next parts of the code is to set the size to 200%, but you can adjust this to what you like. Also you need to make a new broadcast called "what name", and {answer} represents the round answer block from sensing. Aside from that I'm going to write out the rest of the code.

When I receive stitch chosen:
set size to 200%
show
Repeat [length of "colours"]:
if {not ["colour name values" contains item (name count) of "colours"]}:
set (value of colour) to [item (name count) of "colours"]
add (value of colour) to "colour name values"
broadcast what name
ask [what do you wnat to name this colour?] and wait
and {answer} to "colour names"
repeat until {not ["replace colour #" contains (value of colour)]}:
replace item [item # of (value of colour) in "replace colour #"] of "replace colour #" with {answer}
change (name count) by 1
hide
broadcast write pattern

*If you made it possible to choose whether to name them then replace the 'when I receive stitch chosen' with when clicked.

Track How Many in a Row

Screenshot 2023-06-21 144635.png

Now we need to make it track how many in a row. Start by making 3 variables, one called "times width", one "how many in a row", one "count", and make a list called "how many in a row". Then get a 'when green flag clicked' block and underneath it put 'set how many in a row to 0' and 'set count to 0' from variables, 'delete all of how many in a row' from lists, and a hide (this sprite is never supposed to show, just to count things in the background).

Once again I'm just going to write out the rest of the code.

When I receive write pattern:
set (times width) to 0
set (count) to 0
set (how many in a row) to 0
Repeat (height):
change (times width) by 1
Repeat (width):
change (count) by 1
if [(count) + 1] = {[(width) * (times width)] + 1} then:
add [item (count)] of "replace colour #" to "how many in a row"
add (how many in a row) to "how many in a row"
add End of row to "how many in a row"
add End of row to "how many in a row"
set (how many in a a row) to 1
else:
if {[item (count)] of "replace colour #"} = {[item (count) + 1] of "replace colour #"} then:
change (how many in a a row) by 1
else:
add [item (count)] of "replace colour #" to "how many in a row"
add (how many in a row) to "how many in a row"
set (how many in a a row) to 1

Write the Final Pattern

Screenshot 2023-06-21 150933.png

You're going to start by making a new sprite. For its costume type out "finished pattern" and cover the screen with white underneath the text (this sprite will pretty much act as a backdrop). Then you need to make four new variables, called "name tracker", "number tracker", "row", and "finished pattern". You also need two new lists, "individual row" and "pattern". Start with a when green flag clicked, and under it put 'hide', 'delete all of _' for individual row and pattern, 'set name tracker to 1', 'set number tracker to 2', and 'hide variable finished pattern'.

You also need to get a when green flag clicked button and under it set all the variables to 0, and delete all of all the lists. This is just so everything resets at the beginning

This is probably the longest code in the entire thing, so once again I'm just writing it out. Also things that are just plain text in this one will have ", and lists will have ' instead.

When I receive write pattern:
go to front layer
show
set (finished pattern) to 0
wait 2 seconds
add {join ["Abbreviations: Ch = chain,"{join (abbreviation) [join "="(stitch type)]}]} to 'pattern'
add [join "Round 1: Slip knot, ch" (width)] to pattern
set (row) to 1
Repeat (height):
change (row) by 1
if {[{[item (name tracker) of 'how many in a row'] = "End of row} or {[item (number tracker) of 'how many in a row'] = "End of row"}] and (number tracker) = 4} then:
delete all of 'individual row'
change (name tracker) by 2
change (number tracker) by 2
if {[{[item (name tracker) of 'how many in a row'] = "End of row"} or {[item (number tracker) of 'how ma ny in a row'] = "End of row"}] and [not(number tracker) = 4]} then:
add [join 'individual row' ", ch 1, turn."]
delete all of 'individual row'
change (name tracker) by 2
change (number tracker) by 2
add [join "Round " {join (row) [join ": " {join [join "Using " [item (name tracker) of 'how many in a row'] {join ", " [join (abbreviation) {join " " [item (number tracker) of 'how many in a row']}]}]}]}] to 'individual row'
if {not [{(name tracker) = [item # of "End of row" in 'how many in a row']} or {(name tracker) = [item # of "End of row" in 'how many in a row']}]} then:
change (name tracker) by 2
change (number tracker) by 2
if {not [item (name tracker) of 'how many in a row' = (width)]} then:
repeat until [{[item (name tracker) of 'how many in a row'] = "End of row"} or {[item (number tracker) of 'how many in a row'] = "End of row"}]
add {join ", change to" [join [item (name tracker) of 'how many in a row'] {join ", " [join (abbbreviation) {join " " [item (number tracker) of 'how many in a row']}]}]} to 'individual row'
change (name tracker) by 2
change (number tracker) by 2
add "Cut yarn and pull through loop. You're finished, congrats! :)" to 'pattern'
set (finished pattern) to 'pattern'
show variable (finished patterns)
add [join 'individual row' ", ch 1, turn."] to 'pattern'
delete all of 'individual row'

You're done!!!!!!!!!!

My Final Version

Here's the link to mine :)

CrochetPatternMaker