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

/
Lesson 4.4 - Motion and Multiple Reactor Points

Lesson 4.4 - Motion and Multiple Reactor Points

Dec 07, 2015

int gridWidth = 30;
int gridHeight = 30;
float shapeWidth = 20; 
float shapeHeight = 20; 
float reactorScaler = .02;
int amplitude = 2;
int xOffset;
int yOffset;
ArrayList<reactorPoint> reactorList = new ArrayList<reactorPoint>();
ArrayList<graphicObject> graphicList = new ArrayList<graphicObject>();


void setup() {
  size(800, 800);
  xOffset = floor(width/2-(shapeWidth*gridWidth/2));
  yOffset = floor(height/2-(shapeHeight*gridHeight/2));

  reactorPoint temp = new reactorPoint(400, 400);
  reactorList.add(temp);

  background(255);
  noFill();

  for (int i = 0; i<gridWidth; i++ ) {
    for (int j = 0; j<gridHeight; j++ ) { 
      graphicList.add(new graphicObject(i*shapeWidth, j*shapeHeight));
    }
  }
};

void draw() {
  background(255);
  pushMatrix(); 
  translate(xOffset, yOffset); //translate array to center of screen

  for (int i = 0; i<reactorList.size(); i++ ) {
    reactorList.get(i).count();
  }
  println("reactorList.size() "+reactorList.size());

  for (int i = 0; i<graphicList.size(); i++ ) {
    graphicList.get(i).draw(reactorList);
  }
  popMatrix();
};



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

int mouse_Y() {
  return (mouseY - xOffset); //correct positions matrix translations
}
void mouseClicked() {
  reactorPoint temp = new reactorPoint(mouse_X(), mouse_Y());
  reactorList.add(temp);
};

class graphicObject {
  PVector _loc;
  float _scale = 1.0;

  graphicObject(float x, float y) {
    _loc = new PVector(x, y);
  }

  void draw(ArrayList<reactorPoint>  reList) {
    float reactorDistance = 0;
    int myStartTime = 0;
    float n = 0;
    _scale = 1.0;

    for (int i = 0; i<reList.size(); i++) {
      reactorDistance = dist(reList.get(i)._loc.x, reList.get(i)._loc.y, _loc.x, _loc.y);
      myStartTime = int(reList.get(i)._counter-reactorDistance);
      n = radians(myStartTime)*1.5;
      _scale += sin(n)*amplitude;
    }
    _scale = _scale/reList.size();
    pushMatrix();
    translate(_loc.x, _loc.y);
    scale(_scale);

    strokeWeight(0.2);
    ellipse(0, 0, shapeWidth, shapeHeight);
    popMatrix();
  }
}

class reactorPoint {

  PVector _loc;
  int _counter;

  reactorPoint (int x, int y) {
    _counter = 0; 
    _loc = new PVector(x, y);
  }

  void count() {
    _counter++;
  }
}
, multiple selections available,
{"serverDuration": 41, "requestCorrelationId": "4e40b8a1d43549b08ceb2ffd9e21dec4"}