# Enable collisisons

**URL:** https://discourse.processing.org/t/enable-collisisons/17231
**Category:** Libraries
**Created:** [January 21, 2020, 5:18pm UTC](https://discourse.processing.org/t/enable-collisisons/17231 "2020-01-21T17:18:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![floflopm](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@floflopm](https://discourse.processing.org/u/floflopm)
#### Post date: [January 21, 2020, 5:18pm UTC](https://discourse.processing.org/t/enable-collisisons/17231/1 "2020-01-21T17:18:25Z")

</div>

Hi,

I currently have a script in which some pixels are bouncing all over the screen with a damping effect and I can draw lines. I would like to find a way to make the pixels bounce on the lines (the lines would become obstacles), but I don’t know how to write this as the two elements come from different parts of my script. I am using the Fisica library for the lines.

Thank you,

```auto

int cols;
int rows;
float[][] current;// = new float[cols][rows];
float[][] previous;// = new float[cols][rows];
float dampening = 1;

import fisica.*;

FWorld mundo;
FBox caja;

float x, y;
//--------------------------------------------------------------------------------

void setup() {
  size(500, 500); // ratio/size changes interactions between waves. the window represents our horizon;
  
  smooth();
  
  Fisica.init(this);
  
  mundo = new FWorld();
  mundo.setEdges();
  
  frameRate(24);
  
//--------------------------------------------------------------------------------  

  cols = width;
  rows = height;
  current = new float[cols][rows];
  previous = new float[cols][rows];
}

void mouseMoved() {
  previous[mouseX][mouseY] = 400; // changes intensity of ripple
}
  
void mouseClicked(){ // makes concentric circles
 previous[mouseX][mouseY] = 2000;

}

//--------------------------------------------------------------------------------

void draw() {
  background (0);
  
  loadPixels();
  for (int i = 1; i < cols-1; i++) {
    for (int j = 1; j < rows-1; j++) {
      current[i][j] = (
        previous[i-1][j] + 
        previous[i+1][j] +
        previous[i][j-1] + 
        previous[i][j+1]) / 2 -
        current[i][j];
      current[i][j] = current[i][j] * dampening;
      int index = i + j * cols;
      pixels[index] = color(current[i][j]);
    }
  }
  
  updatePixels();

  float[][] temp = previous;//ripple. if disables, only creates static pixels
  previous = current;
  current = temp;

//---------------------------
 fill(0, 20);
  noStroke();
  rect(0, 0, width, height);
  
 mundo.step();
 mundo.draw(this);

//--------------print frame---------------------------
 if (keyPressed == true) { //to save images every x seconds and make a movie
    if (key == 'p'){
      saveFrame("ondes-###.png");
    }
    }
}

//-------------- make a line-------------------------
void mousePressed() {
  caja = new FBox(4, 4);
  caja.setStaticBody(true); //true or false
  caja.setStroke(0);
  caja.setFill(0);
  caja.setRestitution(0.9);
  mundo.add(caja);
  
  x = mouseX;
  y = mouseY;
}

void mouseDragged() {
  if (caja == null) {
    return;
  }
  
  float ang = atan2(y - mouseY, x - mouseX);
  caja.setRotation(ang);
  caja.setPosition(x+(mouseX-x)/2.0, y+(mouseY-y)/2.0);
  caja.setWidth(dist(mouseX, mouseY, x, y));
  
}
```

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [January 21, 2020, 11:32pm UTC](https://discourse.processing.org/t/enable-collisisons/17231/2 "2020-01-21T23:32:50Z")

</div>

I would start by doing a google search: queries like “line point collision detection” will return a ton of results. Try to get [small example program](https://stackoverflow.com/help/minimal-reproducible-example) working.

Shameless self-promotion: here is a guide on collision detection in Processing:

> **[Processing Collision Detection](https://happycoding.io/tutorials/processing/collision-detection)**
>
> Learn how to trigger an action when objects overlap in Processing!
