Building a Crochet Pattern with Functions

For this project, I wanted to connect crochet patterns with coding. A crochet chart is made from individual stitch symbols arranged into a larger pattern.

My ultimate goal is to create an interactive crochet pattern builder where users can select stitch symbols and place them on a grid to design their own patterns. For this week, I focused on drawing a fixed pattern using functions and loops.

Each stitch as a function

I created four functions: chain(), single(), halfDouble(), and double(). Each takes an x and y position, so I can draw the same symbol anywhere on the canvas without repeating its drawing instructions.

The main challenge with my interactive idea was figuring out how the program would remember what users had placed in each grid cell.

Calling background() inside draw() clears the canvas every frame. To keep placed stitches visible, the program needs to remember their types and positions and draw them again. Creating a separate variable for every cell would require too much repeated code.

I explored keeping the drawing on the canvas and saving an image of it, but this remembers the appearance rather than which stitch belongs to each cell. I decided to wait until we learn arrays before developing the placement system further.

For the current version, I recreated a fixed pattern near the center of a 25-pixel grid. Each round has a different color, making the structure easier to see.

The pattern() function organizes the design. Loops repeat stitches across the top, bottom, left, and right, while additional calls fill in the corners. The stitch functions remain responsible for drawing the individual symbols.

This version helped me understand how functions can break a larger drawing into manageable parts. Although the pattern is fixed for now, the same stitch functions can become the drawing tools for my future interactive editor.

Screenshot 2026-10-07 at 00.53.56.png