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.
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:
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
.