CSC204 - Project 1
Weaving with Java

Assigned Feb 26th
Due March 7th 2pm


Overview

In this project, you will implement a Java program to display weaving patterns.

Weaving

Weaving is an ancient textile art of making clothing and other fabrics. Almost every piece of fabric you wear has been woven in some fashion. The most common way to weave is through the use of a loom. In a loom, threads are placed vertically through heddles, which are attached to different harnesses. These harnesses are raised or lowered in specific patterns, such that when thread is shuttled through horizontally, it will lie above some threads and below others, thus weaving the threads together. It is the interaction between these harnesses and the threads which creates beautiful patterns in fabric; this interaction is very regular, which makes weaving a perfect task for simulation through a computer program.

Looms have not always had a great history with technology, and in fact some of the first attempts to mechanize the labor industry were met with strong resistance by the Luddite movement. In the early 19th century, Luddites revolted against the coming changes in their industry by smashing looms and promoting violence. This anti-technological sentiment is still alive today in Neo-Luddism.

For this assignment, you will be writing a program in Java to display weaving patterns, much to the chagrin of the Luddites. A sample output from your program for the Sylvia pattern is shown below.

First, let's discuss the data format for our input files.

Data Files

Our weaving data files will have the following format:

H P X Y R
H times P matrix
X numbers between 1 and H
Y numbers between 1 and P

The first 5 numbers in a data file denote the setup for the loom. H is the number of harnesses, P is the number of pedals, X is the number of threads in the warp, Y is the number of threads in the weft, and R is the number of repetitions in each direction.

Next, there is an H by P matrix of 0 and 1, where a 1 denotes that the harness is attached to the particular pedal.

Finally, there are two sets of numbers, first X numbers between 1 and H, to show how each thread of the warp is attached to the harnesses, and then Y numbers between 1 and P, to show how the order of pedals used for each time the shuttle is pushed through to create the weft.

Some example data files can be found here:

What to do

Your task is to write a program capable of reading these files and displaying their patterns, as shown in the above figure. You must name this file Weaver.java. It will first read in all the data from the file and store it appropriately using data structures in Java.

Once the data has been read, your program will draw the resulting pattern to the StdDraw output. Scale the dimensions of StdDraw to be the maximum of X times R and Y times R. For each weft pass, it should examine which pedal is pressed, and therefore which harnesses will be raised. Then for each warp thread, if the harness is raised, it will draw a filled square, otherwise it will draw a normal white square. This is repeated R times in the X and Y dimensions.

To test your program, use the above example data files as standard input. You must also design a pattern of your own, saving it to the file mypattern.txt, and save the output of your pattern as mypattern.jpg.

What to turn in

You should hand in three files to your file space on the cs.centenary.edu server, following the instructions of Lab 1. The files are