Friday, March 6, 2015

Modified Cats Cradle

On March 5, 2015 I turned in this assignment using the knowledge we had learned in class about  if statements and for loops. Essentially all I had to do was modify a code we had already done in class. My previous blog post, "CSE Cats Cradle" is the code that I was expected to modify. Our assignment was is down below.

To exceed expectations, complete all 3. To meet expectations, complete 2. To approach expectations, complete 1.

  1. Create a yarn art/cat’s cradle project that can color in the randomly created polygons.
  2. Create a yarn art/cat’s cradle project where the points are animated and move around the screen with the lines stillCONNECTED.
  3. Create a yarn art/cat’s cradle project where the user can move the points around theWINDOW by clicking and dragging them (the lines should still be connected).
I attempted to do all three of the assignments but was only able complete two, creating a cat cradle that could color in randomly created polygons and to create a cats cradle that had animated points that moved around the screen. Below is the codes I created.

                                                                Cats Cradle Animation
// cat's cradle
int size;
int movex=(2);
int movey=(3);
float[] xPos;
float[] yPos;

void setup() {
 size(850, 700);
 background(0);
 noFill();

 strokeWeight(2);

 size = 3;
 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() {
 background(0);

 for (int i = 0; i < size - 1; i++) {
   for (int j = i + 1; j < size; j++) {

     strokeWeight(5);
     stroke(random(256), random(256), random(256));
     smooth();
     line(xPos[i], yPos[i], xPos[j], yPos[j]);

     xPos[i] = xPos[i] + movex;
     yPos[j] = yPos[j] + movey;

     // (Too far right)
     if (xPos[i] > width) {
       xPos[i]=width;
       movex=-movex;
     }
     // (Too far left)
     if (xPos[i] < 0) {
       xPos[i]=0 ;
       movex = -movex;
     }
     //(Too far down)
     if (yPos[i] > height) {
       yPos[i]=height;
       movey = -movey;
     }
     //(Too far up)
     if (yPos[i] < 0) {
       yPos[i]=0;
       movey = -movey;

       if (xPos[j] > width) {
         xPos[i]=width;
         movex=-movex;
       }
       // (Too far left)
       if (xPos[j] < 0) {
         xPos[j]=0 ;
         movex = -movex;
       }
     }
   }
 } // end of inner for
 // end of outer for
} // end of draw

                                                            Cats Cradle Colored in Polygons
                                                          
// cat's cradle

int size;
float[] xPos;
float[] yPos;
PShape s;

void setup() {
 size(800, 600, P2D);
 background(0);
 strokeWeight(5);
 stroke(255);
 smooth();
 //strokeWeight(2);

 size = 4;
 xPos = new float[size];
 yPos = new float[size];
 s = createShape( );
 s. beginShape();
 s. fill(#EA0909);
 s. noStroke();

 for (int i = 0; i < size; i++) {
   xPos[i] = random(width);
   yPos[i] = random(height);
   s.vertex(xPos[i], yPos[i]);
 } // end of for
 s.endShape(CLOSE);
} // end of setup

void draw() {
 background(0);
 shape(s, 0, 0);
 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