Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Confluence
For you

Programming
Results will update as you type.
  • Tiling and Repetition
  • Reactors
  • Programming Basics: Parametric and Generative Graphic Design 2016
  • Archive
  • High Scores
  • Artificial Neural Network
  • Alternatives to the Processing IDE
  • p5.js Programming
  • Programming in Processing (java)
    • Starting with Processing (en)
    • Variables (en)
    • Classes and Objects (en)
    • Events und Functions (en)
    • Writing our own Functions (en)
    • Random Numbers (en)
    • Conditionals (en)
    • Loops (en)
    • Nested Loops (en)
    • Coordinates (en)
    • Arrays and Lists (en)
    • SVG + Images (en)
    • Motion and Temporality
      • Lesson 4.2 – Sine function
      • Lesson 4.4 - Motion and Multiple Reactor Points
      • Lesson 4.5 - Exercises
      • Motion Reactor
      • Multiple Reactor Points
    • Gesture Interactions
    • Using bitmaps as modifiers
    • Vectors
    • Animation
    • Animation 2
    • Simple Collision Detection
    • Sound
    • Typography

/
Multiple Reactor Points

Multiple Reactor Points

Nov 07, 2017

 

 

 

 

ArrayList<PVector> reactorList = new ArrayList<PVector>();
int maxPointCount = 20;
int gridWidth = 30;
int gridHeight = 30;
float dist_x = 20; 
float dist_y = 20; 
float shapeWidth = 20;
float shapeHeight = 20;
int xOffset;
int yOffset;
float reactorScaler = .003;

void setup() {
  size(800, 800);
  smooth();
}

void draw() {
  background(255);
  xOffset = floor(width/2-(dist_x*gridWidth/2));
  yOffset = floor(height/2-(dist_y*gridHeight/2));
  PVector temp = new PVector(mouse_X(), mouse_Y());
  reactorList.add(temp);
  if (reactorList.size() >= maxPointCount) {
    reactorList.remove(0);
  }
  pushMatrix(); //saves current position of the coordinate system
  translate(xOffset, yOffset);//translate grid to center 
  noStroke();
  fill(0);
  for (int i = 0; i<gridWidth; i++ ) {
    for (int j = 0; j<gridHeight; j++ ) {
      PVector myPos = new PVector(i*dist_x, j*dist_y);
      PVector cpt = closestPoint(myPos);
      float reactorDistance = dist(cpt.x, cpt.y, myPos.x, myPos.y);
      float scaler = reactorDistance*reactorScaler;
      ellipse(myPos.x, myPos.y, shapeWidth*scaler, shapeHeight*scaler);
    };
  };
  //drawReactors();   // unconment to see the trail of reactors created by mouse movement
  popMatrix();
}

void drawReactors() {


  stroke(255, 0, 0);
  for (int i = 0; i <reactorList.size()-1; i++) {
    line(reactorList.get(i).x, reactorList.get(i).y, reactorList.get(i+1).x, reactorList.get(i+1).y);
  }
}

PVector closestPoint(PVector location) {
  PVector tempPoint = reactorList.get(0);
  float bestDistance = dist(tempPoint.x, tempPoint.y, location.x, location.y);
  for (int i = 0; i < reactorList.size(); i++) {
    float tempDistance = dist(reactorList.get(i).x, reactorList.get(i).y, location.x, location.y);
    if (tempDistance<bestDistance) {
      bestDistance = tempDistance;
      tempPoint = reactorList.get(i).get();
    }
  }
  return tempPoint;
}

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

int mouse_Y() {
  return (mouseY - xOffset); //correct positions matrix translations
}

, multiple selections available,
{"serverDuration": 16, "requestCorrelationId": "77a4d5e63e4342f799f141c3ed67d7a6"}