CS111 Lab 3 Answers

Knitting Answers

public Picture labKnit1 (Color c1, Color c2) {
  Picture A1 = A(c1, c2, c1, c1, c2);
  Picture A2 = A(c2,c1,c2,c2,c1);
  Picture B1 = B(c1, c2, c1, c1, c2);
  Picture B2 = B(c2,c1,c2,c2,c1);
  return tileKnit(A1,A2,B1,B2);
}
 
public Picture labKnit2 (Color c1, Color c2) {
  Picture A1 = A(c1,c1,c2,c2,c2);
  Picture B1 = B(c2,c2,c1,c1,c1);
  return tileKnit(clockwise180(B1),flipVertically(A1),B1,flipHorizontally(A1));
}

public Picture labKnit3 (Color c1, Color c2, Color c3, Color c4) {
  Picture p1 = labKnit3Corner(c1,c2,c3,c4);
  Picture p2 = labKnit3Corner(c2,c1,c4,c3);
  return fourSame(fourPics(p1,p1,p2,p2));
}

public Picture labKnit3Corner (Color c1, Color c2, Color c3, Color c4) {
  Picture A1 = A(c4,c3,c2,c2,c1);
  Picture A2 = A(c4,c3,c1,c1,c2);
  Picture B1 = B(c1,c2,c3,c3,c4);
  Picture B2 = B(c2,c1,c3,c3,c4);
  return fourPics(clockwise180(B1),flipVertically(A1),B2,flipHorizontally(A2));
}