Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
Binary file added .coverage
Binary file not shown.
3 changes: 3 additions & 0 deletions .ipynb_checkpoints/README-checkpoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# knitting_pattern
A project in which I attempt to create a tool to help calculate knitting patterns.
My goal is to develop an app where the user can move and scale alpha patterns (patterns on a pixel grid) on a garment, and based on selected measurement, yarn gauge and pattern placement, the app can calculate a knitting pattern to follow.
63 changes: 60 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
# knitting_pattern
A project in which I attempt to create a tool to help calculate knitting patterns.
My goal is to develop an app where the user can move and scale alpha patterns (patterns on a pixel grid) on a garment, and based on selected measurement, yarn gauge and pattern placement, the app can calculate a knitting pattern to follow.
```markdown
# 🧶 Knit App

## About This Project
Knit App is a comprehensive Streamlit-based application designed for knitters and compatible with crocheters and other textile makers. It bridges the gap between digital pixel art and physical garment construction. Users can upload images to generate alpha patterns, calculate garment shaping (Front, Back, and Sleeves) based on gauge and sizing, and edit multiple graphics on a digital canvas.


## Key Features
* **Pattern Digitization:** Upload any PNG/JPG and use dynamic thresholding and resampling to convert it into a pixel matrix that you can layer onto a sweater canvas.
* **Multi-Panel Garment IDE:** Switch between Front Panel, Back Panel, and Sleeves canvases that make up a drop shoulder sweater. The app dynamically calculates dimensions and short-row shaping based on user measurements and gauge.
* **Layer Design Studio:** Add, duplicate, merge, and transform (rotate, flip, mirror, scale) multiple graphics on a single canvas.
* **Fine-Tune Pixel Editor:** A built-in, manual spreadsheet-style editor to fine-tune individual stitches or draw custom motifs from scratch on blank 25x25 or 50x50 canvases.
* **Alpha JSON exporter:** Export your custom design to a JSON file to reuse in future projects.
* **Master PDF Compiler:** Automatically chunks your digital canvas into a printable PDF pattern complete with cast-on counts, row instructions, and sweater specs.
* **Project Saving:** Serialize your entire workspace (including layers, settings, and math grids) into a JSON file to resume your work later.


## Prerequisites
Before installing, ensure you have **Python 3.9 or newer** installed on your system. We highly recommend using a virtual environment (like `venv` or Anaconda) to keep dependencies clean.


## Installation

### Option A: Using GitHub Desktop
1. Download and install [GitHub Desktop](https://desktop.github.com/).
2. Open GitHub Desktop and go to **File > Clone repository**.
3. Select the **URL** tab and paste: `https://github.com/Programming-The-Next-Step-2026/knitting_pattern.git`
4. Choose a local path on your computer and click **Clone**.
5. Open your preferred terminal (or Anaconda Prompt) and navigate to the folder you just cloned.
6. Run the following command to install the package and its dependencies:
pip install -e .


### Option B: Command Line (Windows / Mac / Linux)
1. Open your Terminal/Command Prompt/PowerShell.
2. Clone the repository:
git clone [https://github.com/Programming-The-Next-Step-2026/knitting_pattern.git](https://github.com/Programming-The-Next-Step-2026/knitting_pattern.git)

3. Navigate into the directory:
cd knitting_pattern

4. Install the package:
pip install -e .


## Usage
Once installed, make sure your in the knitting_pattern directory, then run the application locally:
streamlit run src/knitting_pattern/app.py

This will automatically open the Knit App dashboard in your default web browser.

## Project Architecture

* **`app.py`:** The Streamlit UI layer acting as the bridge for state management and user interaction.
* **`math_engine.py`:** Calculates physical measurements, gauge conversions, and garment topography (like short row geometry).
* **`image_engine.py`:** Handles digital formatting, utilizing Pillow and NumPy for image resampling, bounding box cropping, and Matplotlib for dynamic PDF generation.

## License

Distributed under the MIT License. Built for the course *Programming: The Next Step (2026)*.
Binary file modified app_generated_chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 18 additions & 7 deletions docs/.ipynb_checkpoints/report-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@
"source": [
"2. Software Architecture\n",
"The software uses the standard Python src/ layout to isolate core business and graphical logic from the presentation layer.\n",
"\n",
"Stitch and Row Allocation: The engine converts user dimensions (in centimeters) to absolute integers. \n",
"It uses ceiling rounding (math.ceil) since a knitter cannot execute a partial stitch. The underlying formula is:\n",
"stitches = [{width (cm)} * {stitch gauge} / 10)]\n",
"\n",
"Grid Canvas Representation: The backend models the fabric as a two-dimensional grid (nested lists or arrays). Unoccupied background fabric is initialized to 0.\n",
"Alpha Pattern Integration: The system reads pixel-based assets representing the alpha design. It maps these coordinates directly onto the sweater grid, reassigning target cells from background 0 to specific integer color IDs (e.g., 1, 2, 3). This acts as the layout for the color chart."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc4d6fcd-c5f0-4b80-b409-8c4fc66b0922",
"metadata": {},
"outputs": [],
"source": [
"Current layout:\n",
"knitting_pattern/\n",
"├── src/\n",
"│ ├── knitting_pattern/\n",
Expand All @@ -29,13 +46,7 @@
"│ │ └── image_engine.py # Visualization logic, plotting chart and recognizing alpha patterns\n",
"│ └── tests/\n",
"│ ├── test_image_engine.py\n",
"│ └── test_math_engine.py \n",
"Stitch and Row Allocation: The engine converts user dimensions (in centimeters) to absolute integers. \n",
"It uses ceiling rounding (math.ceil) since a knitter cannot execute a partial stitch. The underlying formula is:\n",
"stitches = [{width (cm)} * {stitch gauge} / 10)]\n",
"\n",
"Grid Canvas Representation: The backend models the fabric as a two-dimensional grid (nested lists or arrays). Unoccupied background fabric is initialized to 0.\n",
"Alpha Pattern Integration: The system reads pixel-based assets representing the alpha design. It maps these coordinates directly onto the sweater grid, reassigning target cells from background 0 to specific integer color IDs (e.g., 1, 2, 3). This acts as the layout for the color chart."
"│ └── test_math_engine.py "
]
},
{
Expand Down
43 changes: 34 additions & 9 deletions docs/report.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"id": "73620923-8165-4d80-a81a-cb768294cc6f",
"metadata": {},
"source": [
"Week 3 Assignment: Knitting Pattern Calculator Project Report\n",
"\n",
"1. Project Overview\n",
"Knitting a custom sweater from the top down requires translating physical body measurements into a discrete grid of stitches and rows based on a individual knitting gauge. Manual conversion often leads to structural math errors. Furthermore, knitters wanting to incorporate multi-colored intarsia or stranded motifs (\"alpha patterns\") must manually map those pixel charts onto their specific garment dimensions, which is a slow and error-prone process.\n",
"\n",
Expand All @@ -20,6 +18,23 @@
"source": [
"2. Software Architecture\n",
"The software uses the standard Python src/ layout to isolate core business and graphical logic from the presentation layer.\n",
"\n",
"Stitch and Row Allocation: The engine converts user dimensions (in centimeters) to absolute integers. \n",
"It uses ceiling rounding (math.ceil) since a knitter cannot execute a partial stitch. The underlying formula is:\n",
"stitches = [{width (cm)} * {stitch gauge} / 10)]\n",
"\n",
"Grid Canvas Representation: The backend models the fabric as a two-dimensional grid (nested lists or arrays). Unoccupied background fabric is initialized to 0.\n",
"Alpha Pattern Integration: The system reads pixel-based assets representing the alpha design. It maps these coordinates directly onto the sweater grid, reassigning target cells from background 0 to specific integer color IDs (e.g., 1, 2, 3). This acts as the layout for the color chart."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc4d6fcd-c5f0-4b80-b409-8c4fc66b0922",
"metadata": {},
"outputs": [],
"source": [
"Current layout:\n",
"knitting_pattern/\n",
"├── src/\n",
"│ ├── knitting_pattern/\n",
Expand All @@ -29,13 +44,7 @@
"│ │ └── image_engine.py # Visualization logic, plotting chart and recognizing alpha patterns\n",
"│ └── tests/\n",
"│ ├── test_image_engine.py\n",
"│ └── test_math_engine.py \n",
"Stitch and Row Allocation: The engine converts user dimensions (in centimeters) to absolute integers. \n",
"It uses ceiling rounding (math.ceil) since a knitter cannot execute a partial stitch. The underlying formula is:\n",
"stitches = [{width (cm)} * {stitch gauge} / 10)]\n",
"\n",
"Grid Canvas Representation: The backend models the fabric as a two-dimensional grid (nested lists or arrays). Unoccupied background fabric is initialized to 0.\n",
"Alpha Pattern Integration: The system reads pixel-based assets representing the alpha design. It maps these coordinates directly onto the sweater grid, reassigning target cells from background 0 to specific integer color IDs (e.g., 1, 2, 3). This acts as the layout for the color chart."
"│ └── test_math_engine.py "
]
},
{
Expand Down Expand Up @@ -71,6 +80,22 @@
"\n",
"Solution: Expand the mathematical backend to calculate complex raglan lines and set-in sleeve caps. This requires developing dynamic decrease formulas to scale diagonal stitch lines across the grid canvas while maintaining the integrity of the centered alpha patterns."
]
},
{
"cell_type": "markdown",
"id": "e66e80a0-6441-43dd-b2bc-04f0bb39cc53",
"metadata": {},
"source": [
"Things to implement before Friday:\n",
"1. manual pixel editor in case the pixel converter isnt perfect (still in developement - prototype exists)\n",
"2. sleeves (DONE)\n",
"3. multiple alpha patterns on one thing - to edit them you click on the sidepanel on one of the alpha patterns and edit like normal. (DONE)\n",
"5. Be able to copy an alpha pattern for continuous 'stripe' or to make a repeating pattern (maybe through the multiple alpha pattern added or have like a choice to make a vertical or horizontal repeating pattern from one alpha pattern? maybe even a hexagonal grid, square grid? offset vertical stripes over some parts of the sweater? (DONE)\n",
"6. make more unit tests that have good coverage (see julians comments) (no progress)\n",
"7. have the whole pattern in one pdf; so be able to have separate 'projects' at once: front panel, back panel, and sleeves. so we can design alpha patterns and fit for each aspect of the sweater and then put everything in one pdf pattern with the title of the project that we chose and the rest of the instructions. (DONE)\n",
"8. save JSON file of current session so you don't loose progress and can import the JSON file to start back on (DONE)\n",
"9. README file update to include the instructions of download and use. (no progress)"
]
}
],
"metadata": {
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ description = "Kitting pattern calculator tool for my programming course"
readme = "README.md"
requires-python = ">=3.9"
dependencies = [
"numpy",
"Pillow",
"streamlit",
"matplotlib"
"numpy>=1.24.0",
"Pillow>=9.1.0",
"streamlit>=1.30.0",
"matplotlib>=3.5.0",
"pandas>=1.5.0"
]
classifiers = [
"Programming Language :: Python :: 3",
Expand Down
Binary file modified src/.DS_Store
Binary file not shown.
Binary file added src/all_over_pattern.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/alphabet.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/alphabet.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/cat_nonpix.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/cow_nonpix.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/diva.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/eyes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/flower_repeating.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 22 additions & 11 deletions src/knitting_pattern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@
@author: kasteivanauskaite
"""

from .example import add, calculate_mean
# src/knitting_pattern/__init__.py

# engine/__init__.py

# This exposes these specific functions to the rest of your app
from .math_engine import (
calculate_stitches, calculate_rows, calculate_garment_dimensions,
calculate_top_down_shoulder_shaping, generate_panel_grid, apply_top_down_mountains_to_grid,
calculate_back_neck_shaping, apply_back_short_rows_to_grid
calculate_stitches,
calculate_rows,
calculate_garment_dimensions,
calculate_top_down_shoulder_shaping,
generate_panel_grid,
apply_top_down_mountains_to_grid,
calculate_back_neck_shaping,
apply_back_short_rows_to_grid
)

# Expose Image Engine Functions
from .image_engine import (
get_hardcoded_heart,
scale_pattern_matrix_integer,
overlay_pattern_on_grid,
generate_chart_image
)
apply_transforms,
get_matrix_dimensions,
overlay_stamps_on_grid,
generate_multipage_pdf_figs,
process_uploaded_image,
rotate_matrix,
generate_cropped_canvas_png_bytes,
merge_stamps,
crop_matrix_to_bounding_box,
serialize_project_state,
deserialize_project_state
)

Loading
Loading