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
    • Simple Reactor
    • Vector Fields
    • Bitmap or SVG Permutations
    • (Extra) Curve Reactor
    • Lesson 2.4 - Exercises
    • 3D 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)

/
Simple Reactor

Simple Reactor

Nov 27, 2017

int gridWidth = 20; 
int gridHeight = 20; 
float shapeWidth = 30; 
float shapeHeight = 30; 
float reactorScaler = .06;
int xOffset;
int yOffset;
PVector reactorPosition;

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

  background(255);
  smooth();
};

void draw() {
  background(255);
  fill(0);
  noStroke();
  pushMatrix(); 
  translate(xOffset, yOffset);//translate matrix to center 
  for (int i = 0; i<gridWidth; i++ ) {
    for (int j = 0; j<gridHeight; j++ ) {
      PVector myPos = new PVector(i*shapeWidth, j*shapeHeight);
      float reactorDistance = dist(reactorPosition.x, reactorPosition.y, myPos.x, myPos.y);
      float scaler = reactorDistance*reactorScaler;
      ellipse(myPos.x, myPos.y, 1*scaler, 1*scaler);
    };
  };
  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();
};


 

 

 

 

, multiple selections available,
{"serverDuration": 10, "requestCorrelationId": "14bfac8db2b2449382dff5a9f44c5886"}