On February 26, 2015 my teacher showed my class how to make a Cats Cradle so that we could later alter the code to make the cats cradle behave differently. Below is the code that my teacher taught to the class.
// cat's cradle
int size;
float[] xPos;
float[] yPos;
void setup() {
size(800, 600);
background(0);
strokeWeight(5);
stroke(160, 40, 160);
smooth();
//strokeWeight(2);
size = 5;
xPos = new float[size];
yPos = new float[size];
for (int i = 0; i < size; i++) {
xPos[i] = random(width);
yPos[i] = random(height);
} // end of for
} // end of setup
void draw() {
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; j < size; j++) {
line(xPos[i], yPos[i], xPos[j], yPos[j]);
} // end of inner for
} // end of outer for
} // end of draw
No comments:
Post a Comment