
The mathematics of weaving patterns.
The Girl with Two Loves
In a small village near Imphal, where the hills fold into each other like sleeping animals, there lived a girl named Thoibi who loved two things: weaving and music.
Her mother was the finest basket weaver in the village. She wove baskets from bamboo strips so thin they bent like grass, creating patterns that looked like the scales of a fish or the petals of a lotus. Thoibi had learned to weave from her, and by the age of ten, her baskets were almost as good as her mother's.
But Thoibi also loved the pena — the one-stringed fiddle that travelling musicians played at festivals. The sound of the pena made her heart ache in a way she couldn't explain, as if the instrument were singing a song she almost remembered.
"You must choose," said her mother one morning. "Weaving takes your whole mind. You cannot weave and play music. Your hands will get confused."
The Travelling Musician
That autumn, a pena player came to the village for the Lai Haraoba festival. His name was Tomba, and he was old, with fingers so crooked they looked like bamboo roots. But when he played, the whole village stopped to listen.
Thoibi sat at his feet during every performance. After the last one, she gathered her courage. "Pena-tompok," she said, "will you teach me to play?"
Tomba looked at her hands. "You are a weaver," he said. It wasn't a question — he could see the calluses.
"Yes. My mother says I must choose between weaving and music."
Tomba smiled, showing gaps where teeth used to be. "Your mother is wise, but she is wrong about this one thing. Come, bring me one of your baskets."
The Hidden Pattern
Thoibi brought her finest basket — a round, lidded container with a pattern of interlocking diamonds. Tomba held it up and turned it slowly in the firelight.
"Tell me," he said, "when you weave, do you count?"
"Of course," said Thoibi. "Over two, under one. Over two, under one. Then shift by one and repeat. That's how you make the diamond pattern."
"Over two, under one. Over two, under one," Tomba repeated — but this time he sang the words, tapping his foot. The counting became a rhythm. The rhythm became a melody. The pattern of the basket became a song.
Thoibi's eyes went wide. "They're the same," she breathed. "The weaving pattern and the music pattern — they're the same thing."
"Everything beautiful has a pattern," said Tomba. "The dancer counts steps. The drummer counts beats. The weaver counts strands. The numbers are the same — only the material changes."
The New Weave
Tomba stayed in the village for a week, and every evening he taught Thoibi to play the pena. She learned quickly — her weaver's fingers were already used to counting, to rhythm, to repetition. The patterns she had woven into bamboo, she now wove into sound.
And something surprising happened. Her baskets got better. When she wove now, she hummed the pena melodies, and the music kept her counting steady, her rhythm even, her patterns flawless. The weaving fed the music, and the music fed the weaving.
Her mother picked up a new basket Thoibi had made and turned it over in her hands. The pattern was more complex than anything she had seen — diamonds within diamonds, each one perfectly aligned.
"How did you do this?" her mother asked.
"I sang it first," said Thoibi.
The Weaver's Song
When Tomba left the village, he gave Thoibi his old pena. "You don't need to choose," he said. "A weaver who plays music makes better baskets. A musician who weaves makes better songs. The world doesn't ask you to be one thing."
Thoibi grew up to be both — the finest basket weaver and the finest pena player in her village. And she taught her own daughters the same lesson: that the rhythm of the loom and the rhythm of the song are sisters, born from the same counting, the same patience, the same love of pattern.
In Manipur, they still say that the best weavers are the ones who sing while they work. Now you know why.
The end.
Choose your level. Everyone starts with the story — the code gets deeper as you go.
Here is a taste of what Level 1 looks like for this lesson:
# Generate a weaving pattern from a counting rule
# Each cell is either OVER (1) or UNDER (0)
rows, cols = 8, 16
over, under, shift = 2, 1, 1 # twill weave
for row in range(rows):
line = ""
offset = (row * shift) % (over + under)
for col in range(cols):
pos = (col + offset) % (over + under)
line += "█" if pos < over else "░"
print(line)
# Try changing over=1, under=1 for plain weave
# Or over=3, under=1, shift=2 for satin weaveThis is just the first of 6 coding exercises in Level 1. By Level 4, you will build: Generate Weaving Patterns Algorithmically.
By Level 4, enrolled students build: Generate Weaving Patterns Algorithmically
Free
Level 0: Listener
Stories, science concepts, diagrams, quizzes. No coding.
You are here
Level 0 is always free. Coding levels (1-4) are part of our 12-Month Curriculum.
The mathematics of weaving patterns.
The big idea: "The Basket Weaver's Song" teaches us about Mathematics of Weaving & Patterns — and you don't need to write a single line of code to understand it.
In the story, old Tomba asks Thoibi how she makes her diamond pattern. Her answer: 'Over two, under one. Over two, under one. Then shift by one and repeat.' That is a counting rule — a set of instructions that, when followed exactly, produces a pattern. No drawing required. No artistic talent. Just counting.
Try this right now. Interlace your fingers loosely. Your fingers are going over-one-under-one-over-one-under-one. That is the simplest weaving pattern — called plain weave. Every strip crosses over one neighbour, then under the next, then over, then under. The result is a grid of tiny squares, like graph paper.
Now imagine changing the rule. Instead of over-1-under-1, you go over-2-under-1. And on the next row, you shift everything one position to the right. Now the 'over' sections create diagonal lines running across the fabric. This is called twill weave — it is how denim jeans are made. Change the counting rule again (say, over-3-under-1 with a shift of 2) and you get a completely different pattern.
What Thoibi is following is called an algorithm — a word that sounds complicated but is not. An algorithm is simply a list of steps you follow in order to complete a task. A recipe is an algorithm: step 1, chop onions; step 2, heat oil; step 3, fry until golden. Done — three steps, task complete. Some algorithms have a loop built in: a weaving pattern says step 1, go over 2; step 2, go under 1; step 3, shift one position; step 4, go back to step 1. That loop is what creates the repeating pattern. But the key idea is the same: follow the steps exactly, and you get the same result every time — no guessing, no talent needed, just counting.
The stunning thing is: every weaving pattern in the world — from Thoibi's Manipuri baskets to Scottish tartans to Japanese sashiko — is nothing more than an algorithm. Different numbers, different shifts, different results. Change the counting rule and you change the pattern. A computer program is also an algorithm — just written in code instead of bamboo. The weaver was programming 5,000 years before computers existed.
Check yourself: If you weave over-1-under-1 you get a grid of tiny squares. If you weave over-2-under-1 with a shift, you get diagonal stripes. What would over-1-under-1-over-1-under-3 produce? (Hint: the long 'under-3' sections would create wide horizontal bands separated by thin gridded rows.)
Key idea: An algorithm is a list of steps you follow in order to complete a task. A recipe, a weaving pattern, and a computer program are all algorithms. Weaving algorithms loop — and the three numbers (over how many, under how many, shift by how many) determine the pattern.
Pick up a single sheet of paper. Bend it. Trivially easy — paper is weak. Now roll it into a tube. Try to crush the tube from the ends. Suddenly it is surprisingly strong. The same material, arranged differently, has completely different strength. Weaving does the same trick with bamboo.
A single bamboo strip is thin, flexible, and weak — you can snap it with one hand. But when you interlace 20 strips tightly in a grid, each strip locks every other strip in place. Try to pull one strip out and it is held by friction at every crossing point. Try to push the basket sideways and each strip resists because it is pinned by the strips running the other direction. The whole thing is rigid, even though every individual piece is floppy.
Here is a key insight: squares are weak, but triangles are strong. Make a square frame from four sticks with loose joints at the corners. Push one corner sideways and the whole thing collapses into a diamond — it has no resistance. Now add one diagonal stick, turning the square into two triangles. Try pushing again. It will not budge. The diagonal locks the shape.
This is why traditional weavers in Assam and Manipur often add diagonal strips to their baskets. The basic over-under grid gives you squares. Adding strips at 60° angles turns those squares into triangles — and the basket becomes dramatically stronger. The same principle is why bridges have criss-crossing beams, bicycle frames use triangular tubes, and geodesic domes are made of triangles.
Try this: Make a square from four pencils and tape the corners loosely. Push one corner — it collapses. Now tape a fifth pencil diagonally across the square. Push again. The triangle holds.
Key idea: Weaving turns floppy strips into rigid structures because each crossing point locks the strips in place. Adding diagonal elements creates triangles — the strongest shape in engineering.
Access all 130+ lessons, quizzes, interactive tools, and offline activities
Old Tomba turned Thoibi's weaving instructions into a song: 'Over two, under one. Over two, under one.' The counting became a **rhythm**. And that is ...
Look at any woven surface — a basket, a mat, a piece of cloth. At every single crossing point, a strip is either **over** or **under**. There is no th...