Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Code Block
//Reactor
//“Make an object respond to the proximity of another object.”
PShape basicShape;
int arrayWidthint gridWidth = 20; 
int arrayHeightgridHeight = 20; 
float shapeWidth = 2030; 
float shapeHeight = 2030; 
float reactorScaler = .0206;
int screenWidth = 700;
int screenHeight = 700;
int xOffset = floor(screenWidth/2-(shapeWidth*arrayWidth/2));
int yOffset = floor(screenHeight/2-(arrayHeight*shapeHeight/2));
PVector reactorPosition;


void setup() {
    
   reactorPosition = new PVector(0, 0);
        size(screenWidth700,screenHeight 700);
  // offset used to center the background(255);graphics on the screen
  xOffset   smooth()= floor(width/2-(shapeWidth*gridWidth/2));
  yOffset = floor(height/2-(gridHeight*shapeHeight/2));

  basicShape = loadShape("data/circle.svg"background(255);
  smooth();
};


void draw() {
  background(255);
  fill(0);
  noStroke();
  pushMatrix(); 
  translate(xOffset, yOffset);//translate arraymatrix to center 
  for (int i = 0; i<arrayWidthi<gridWidth; i++ ) {
     for for(int j = 0; j<arrayHeightj<gridHeight; j++ ) {
  
       shapeMode(CENTER); 
          PVector myPos = new PVector(i*shapeWidth, j*shapeHeight);
   
      float reactorDistance = dist(reactorPosition.x, reactorPosition.y, myPos.x, myPos.y);
   
      float scaler = reactorDistance*reactorScaler;
          fill(0);
          shape(basicShape, ellipse(myPos.x, myPos.y, shapeWidth1*scaler, shapeHeight1*scaler);
          stroke(255,0,0);
          //line(posX, posY, reactorPosition.x, reactorPosition.y); //show line to reactor position
 
      };
  };
  popMatrix();
};


int mouse_X() {
  return (mouseX - xOffset); //correct positions after matrix translations
}


int mouse_Y() {
  return (mouseY - xOffset); //correct positions after matrix translations
}
  void mouseMoved() {
 
        reactorPosition.x = mouse_X();
    
     reactorPosition.y = mouse_Y();
};

};

Exercise: Create two new examples by modifying the code with different reactor shapes that respond not only with size change. Try rotation, colour change or deformations.