FSOSS 2010/processing.js/vector ex

From CDOT Wiki
Jump to: navigation, search
/*
  FSOSS 2010
  Andor Salga
  Collision Detection - Add the appropriate code wherever you see !!!
*/

// !!! create two PVector references to circle positions

int circleSize = 30;

void setup(){
  size(200, 200);
 
  // !!! instantiate circle positions across from one another
}

void draw(){
  background(200);
 
  // !!! move the positions towards each other
 
  // !!! reset the positions if they go past the screen
 
  // change fill color if they collided
  if(collided(circle1, circle2)){
    fill(33, 66, 99, 150);
  }
  else{
    fill(99, 33, 66);
  }
 
  // !!! draw two circles using the positions and diameter of circleSize
}

boolean collided(PVector p1, PVector p2){
 
  // !!! subtract the vectors
 
  // if the magnitude of the result is less
  // than the size of the ball, change color
  if( /*!!!*/ ){
    return true;
  }
  else{
    return false;
  }
}

Answer